C++ armadillo linear algebra library linker error with GCC

  armadillo, c++, linker

I’m getting the following error with GCC >=9 and std>=11 merely by adding the header
#include <armadillo>
to my project.

Undefined symbols for architecture x86_64:
"___emutls_v._ZN4arma19mt19937_64_instanceE", referenced from:
__GLOBAL__sub_I_Test_HPP.cpp in Test_HPP.cpp.o
ld: symbol(s) not found for architecture x86_64
collect2: error: ld returned 1 exit status
make[2]: *** [Test_HPP] Error 1
make[1]: *** [CMakeFiles/Test_HPP.dir/all] Error 2

I’ve tried various hacks including optimization flags e.g. O2, O3 etc. but finally adding the preprocessor header
#define ARMA_DONT_USE_WRAPPER
apparently resolved the issue for now but I need an explanation to feel settled. If the above pre-processor is absolutely necessary to compile the code, should the armadillo library maintainers absorb the macro within the library itself? This kind of issues may take a lot of time to resolve as it is not originated in any programming logic.

Source: Windows Questions C++

LEAVE A COMMENT