Trying to compile using CLion on ubuntu 20.04.5 LTS the example code given in Armadillo documentation but getting errors such as: undefined reference to `arma::arma_rng_cxx11_instance'
here is the code
#include <iostream>
#include <armadillo>
using namespace std;
using namespace arma;
int main()
{
mat A(4, 5, fill::randu);
mat B(4, 5, fill::randu);
cout << A*B.t() << endl;
return 0;
}
I've installed armadillo using sudo apt-get install libarmadillo-dev, and have installed lapack, openBLAS, ARPACK and SuperLU
Here is my makefile:
cmake_minimum_required(VERSION 3.25)
project(ArmadilloSandbox)
set(CMAKE_CXX_STANDARD 17)
find_package(Armadillo REQUIRED)
include_directories(${ARMADILLO_INCLUDE_DIRS})
add_executable(ArmadilloSandbox main.cpp)
target_link_libraries(ArmadilloSandbox ${ARMADILLO_LIBRARIES})
and here is the full error message:
FAILED: ArmadilloSandbox
: && /usr/bin/c++ -g CMakeFiles/ArmadilloSandbox.dir/main.cpp.o -o ArmadilloSandbox /usr/lib/x86_64-linux-gnu/libarmadillo.so && :
/usr/bin/ld: CMakeFiles/ArmadilloSandbox.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]+0x25): undefined reference to `arma::arma_rng_cxx11_instance'
collect2: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.
And if I use the command:
g++ main.cpp -o prog -O2 -larmadillo
I get a similar issue:
/usr/bin/ld: /tmp/cc3o77Vy.o: in function `arma::arma_rng::randu<double>::fill(double*, unsigned long long)':
main.cpp:(.text._ZN4arma8arma_rng5randuIdE4fillEPdy[_ZN4arma8arma_rng5randuIdE4fillEPdy]+0x2a): undefined reference to `arma::arma_rng_cxx11_instance'
/usr/bin/ld: main.cpp:(.text._ZN4arma8arma_rng5randuIdE4fillEPdy[_ZN4arma8arma_rng5randuIdE4fillEPdy]+0x136): undefined reference to `arma::arma_rng_cxx11_instance'
collect2: error: ld returned 1 exit status
despite checking with pkg-config --libs armadillo
which outputs -larmadillo