How to link Armadillo with Eclipse

断了今生、忘了曾经 提交于 2019-12-02 05:48:56

问题


I want to use Armadillo with Eclipse. However all the instructions to link Armadillo is given for Visual Studio. Now I followed the instructions outlined in the ReadMe file of the Armadillo library. I added the Armadillo include folder in project(right click)->properties->C/C++ Build->Settings->Cross G++ Compiler->Includes->Inlcude paths(-I) and then I added the libraries folder (The library folder contain lapack and blas .lib and .dll files) in project(right click)->properties->C/C++ Build->Settings->Cross G++ Linker->Libraries->Library search path (-L).

However when I compile the code in the Eclipse I get the error

.....armadillo_bits/lapack_wrapper.hpp:37: undefined reference to `dgetrf_'.

Shouldn't it simply search for .lib files in the library folder and include them during compiling? I would appreciate any help regarding this matter.

Regards, TM


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/30494610/how-to-link-armadillo-with-eclipse

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