How to link Armadillo with Eclipse

北战南征 提交于 2019-12-02 01:37:27
francis

Linking the Armadillo library to an Eclipse project can be done and you were about to do it ! It's pretty much the same as for any other library.

In the properties of the project :

  • GCC C++ Compiler -> Includes : add the path to the file armadillo (where namespace arma is declared) to the include search path (option -I). Example : /home/alpha/soft/armadillo-4.400.1/include

  • GCC C++ Linker -> Libraries : add the path to the file libarmadillo.so... in the library search path (option -L) Example : /home/alpha/soft/armadillo-4.400.1 . Add armadillo, lapack, blas and m as libraries (option -l). m is for math.

Here are the calls to the compiler and the linker as produced by eclipse :

make all 
Building file: ../src/armaeclip.cpp
Invoking: GCC C++ Compiler
g++ -I/home/alpha/soft/armadillo-4.100.1/include -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"src/armaeclip.d" -MT"src/armaeclip.d" -o "src/armaeclip.o" "../src/armaeclip.cpp"
Finished building: ../src/armaeclip.cpp



Building target: armaeclip
Invoking: GCC C++ Linker
g++ -L/home/alpha/soft/armadillo-4.100.1 -o "armaeclip" ./src/armaeclip.o   -larmadillo -lblas -lm -llapack
Finished building target: armaeclip
**** Build Finished ****

As you run the code, you might get something like :

error: det(): use of ATLAS or LAPACK needs to be enabled terminate called after throwing an instance of 'std::logic_error' what(): det(): use of ATLAS or LAPACK needs to be enabled Abandon (core dumped)

To avoid this problem, follow the advise of the faq of Armadillo : uncomment #define ARMA_USE_LAPACK in file /home/alpha/soft/armadillo-4.100.1/include/config.hpp and rebuild your project.

You can also create GNU Autotools projects and add following line:

bin_PROGRAMS=armadillo_example
armadillo_example_SOURCES=armadillo_example.cpp
armadillo_example_LDADD=-larmadillo

To Makefile.am file where your source code exist.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!