Errors compiling code with armadillo

Hello everyone,

I am using CLion installed on Ubuntu 14.04. When I try to build and run a simple C++ program (in the attachment), that contains Armadillo objects I get the following set of errors:

/opt/clion-1.1/bin/cmake/bin/cmake --build /home/jurij/.clion11/system/cmake/generated/290adae7/290adae7/Debug --target SecondProject -- -j 8
Scanning dependencies of target SecondProject
[ 50%] Building CXX object CMakeFiles/SecondProject.dir/main.cpp.o
[100%] Linking CXX executable SecondProject
CMakeFiles/SecondProject.dir/main.cpp.o: In function `void arma::blas::gemv<double>(char const*, int const*, int const*, double const*, double const*, int const*, double const*, int const*, double const*, double*, int const*)':
/usr/include/armadillo_bits/blas_wrapper.hpp:34: undefined reference to `wrapper_dgemv_'
CMakeFiles/SecondProject.dir/main.cpp.o: In function `void arma::blas::gemm<double>(char const*, char const*, int const*, int const*, int const*, double const*, double const*, int const*, double const*, int const*, double const*, double*, int const*)':
/usr/include/armadillo_bits/blas_wrapper.hpp:69: undefined reference to `wrapper_dgemm_'
CMakeFiles/SecondProject.dir/main.cpp.o: In function `void arma::blas::syrk<double>(char const*, char const*, int const*, int const*, double const*, double const*, int const*, double const*, double*, int const*)':
/usr/include/armadillo_bits/blas_wrapper.hpp:104: undefined reference to `wrapper_dsyrk_'
CMakeFiles/SecondProject.dir/main.cpp.o: In function `double arma::blas::dot<double>(unsigned long long, double const*, double const*)':
/usr/include/armadillo_bits/blas_wrapper.hpp:183: undefined reference to `wrapper_ddot_'
CMakeFiles/SecondProject.dir/main.cpp.o: In function `TLS wrapper function for arma::arma_rng_cxx11_instance':
main.cpp:(.text._ZTWN4arma23arma_rng_cxx11_instanceE[_ZTWN4arma23arma_rng_cxx11_instanceE]+0x5): undefined reference to `TLS init function for arma::arma_rng_cxx11_instance'
main.cpp:(.text._ZTWN4arma23arma_rng_cxx11_instanceE[_ZTWN4arma23arma_rng_cxx11_instanceE]+0x15): undefined reference to `arma::arma_rng_cxx11_instance'
collect2: error: ld returned 1 exit status
make[3]: *** [SecondProject] Error 1
make[2]: *** [CMakeFiles/SecondProject.dir/all] Error 2
make[1]: *** [CMakeFiles/SecondProject.dir/rule] Error 2
make: *** [SecondProject] Error 2



I installed armadillo according to the instructions provided on it's home web page. There were no errors reported during the installation. Moreover if I simply try to build the program in a terminal ( g++ main.cpp -o example -O2 -larmadillo) everything gets compiled without a problem. Hence I assume that the Armadillo is installed correctly and that there are no errors in the code.

I assume that the problem is in my cmake cache or cmakelist.txt. So I tried to add the -larmadillo flag to several linker options in the cache. But that didn't have any effect what so ever. I also tried to find whether I could add the -larmadillo flag to the linker options in the settings, but without any success either.

I am new to c++ and cmake. Therefore any help setting up my IDE environment correctly would be greatly appreciated.

Thank you!
Jurij Sodja



Attachment(s):
CMakeLists.txt.zip
main.cpp.zip
2 comments
Comment actions Permalink

Hi Jurij.

Sorry for the delay. To add libraries to your project you should use find_package command. Please try to add CMake commands from this article. Does that help?

0
Comment actions Permalink

Dear Anna,

thank you for your help. that was indeed what I was missing in my CMakeList.txt file (the three lines marked with # <<<).

Kind regards,
Jurij


cmake_minimum_required(VERSION 3.3)
project(ThirdProject)

find_package(Armadillo REQUIRED) # <<<
include_directories(${ARMADILLO_INCLUDE_DIRS}) # <<<

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")

set(SOURCE_FILES main.cpp)
add_executable(ThirdProject ${SOURCE_FILES})
target_link_libraries(ThirdProject ${ARMADILLO_LIBRARIES}) # <<<
0

Please sign in to leave a comment.