Компиляция работает без ошибок для статического и общего библиотеки.
Но при выполнении test_exec я получаю следующую ошибку, когда построил статическую библиотеку : < /p>
Код: Выделить всё
AddressSanitizer:DEADLYSIGNAL
=================================================================
==19573==ERROR: AddressSanitizer: FPE on unknown address 0x561e54882917 (pc 0x561e54882917 bp 0x7ffea9e6f580 sp 0x7ffea9e6f580 T0)
#0 0x561e54882917 in std::__detail::_Mod_range_hashing::operator()(unsigned long, unsigned long) const (/home/TEST/minimal_example/build_DEBUG/test_exec+0x4917)
#1 0x561e5488855f in std::__detail::_Hash_code_base::_M_bucket_index(unsigned long, unsigned long) const (/home/TEST/minimal_example/build_DEBUG/test_exec+0xa55f)
AddressSanitizer:DEADLYSIGNAL
AddressSanitizer: nested bug in the same thread, aborting
Код: Выделить всё
#ifndef TEST_LIB_H
#define TEST_LIB_H
#include
#include
namespace test {
enum class MyEnum { A, B, C, D };
using enum MyEnum;
const std::unordered_map string_to_enum = {
{"A", A},
{"B", B},
{"C", C},
{"D", D},
};
const std::unordered_map enum_to_string = {
{A, "A"},
{B, "B"},
{C, "C"},
{D, "D"},
};
struct MyStruct {
MyEnum my_enum;
unsigned int num;
bool operator==(const MyStruct &other) const {
return (my_enum == other.my_enum) && (num == other.num);
}
};
struct MyStructHash {
std::size_t operator()(const MyStruct &s) const {
return std::hash{}(s.my_enum) ^
(std::hash{}(s.num)
test_lib.cpp
#include "test_lib.h"
namespace test {
MyMap get_map() {
MyMap map;
map[MyStruct(string_to_enum.at("A"), 2)] = 4.5;
return map;
}
} // namespace test
< /code>
test_exec.cpp
#include "test_lib.h"
#include
using namespace test;
int main(int ac, char **av) {
auto test = string_to_enum.at("A");
std::cout
До сих пор я построил этот минимальный пример, чтобы исключить любые другие проблемы в моем коде. < /p>
Редактировать: < /p>
После определения < /p>
extern const MyMap MAP;
< /code>
в test_lib.h и < /p>
const MyMap MAP = get_map();
Подробнее здесь: https://stackoverflow.com/questions/794 ... ic-library
Мобильная версия