kthohr / mcmc

A C++ library of Markov Chain Monte Carlo (MCMC) methods
https://mcmclib.readthedocs.io/en/latest/
Apache License 2.0
166 stars 45 forks source link

Linker errors when compiling and running the examples #7

Closed natzlob closed 3 years ago

natzlob commented 3 years ago

I have successfully installed mcmc and to run the examples, I copy the file from tests/examples into the main mcmc folder and then compile and build with, for example,g++ hmc_normal.cpp -o hmc_normal -std=c++11 -Iinclude

Then I always get errors related to the call to the specific mcmc type header. In this case:

/tmp/ccanKULh.o: In function `main':
hmc_normal.cpp:(.text+0xc30): undefined reference to `mcmc::hmc(arma::Col<double> const&, arma::Mat<double>&, std::function<double (arma::Col<double> const&, arma::Col<double>*, void*)>, void*, mcmc::algo_settings_t&)'
/tmp/ccanKULh.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*)':
hmc_normal.cpp:(.text._ZN4arma4blas4gemvIdEEvPKcPKiS5_PKT_S8_S5_S8_S5_S8_PS6_S5_[_ZN4arma4blas4gemvIdEEvPKcPKiS5_PKT_S8_S5_S8_S5_S8_PS6_S5_]+0x53): undefined reference to `dgemv_'
/tmp/ccanKULh.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*)':
hmc_normal.cpp:(.text._ZN4arma4blas4gemmIdEEvPKcS3_PKiS5_S5_PKT_S8_S5_S8_S5_S8_PS6_S5_[_ZN4arma4blas4gemmIdEEvPKcS3_PKiS5_S5_PKT_S8_S5_S8_S5_S8_PS6_S5_]+0x5f): undefined reference to `dgemm_'
/tmp/ccanKULh.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*)':
hmc_normal.cpp:(.text._ZN4arma4blas4syrkIdEEvPKcS3_PKiS5_PKT_S8_S5_S8_PS6_S5_[_ZN4arma4blas4syrkIdEEvPKcS3_PKiS5_PKT_S8_S5_S8_PS6_S5_]+0x52): undefined reference to `dsyrk_'
/tmp/ccanKULh.o: In function `double arma::blas::dot<double>(unsigned long long, double const*, double const*)':
hmc_normal.cpp:(.text._ZN4arma4blas3dotIdEET_yPKS2_S4_[_ZN4arma4blas3dotIdEET_yPKS2_S4_]+0x4c): undefined reference to `ddot_'
collect2: error: ld returned 1 exit status

There is a call to mcmc:hmc(***) in the main function of that file, but with a different signature. Similar issues arise with all other examples. All the errors also mention "arma" so I assume this might have to do with linking with armadillo library.

Please assist. Is this to do with linking the headers, or with the namespace resolution? Can anyone assist with this please?

ybwerneck commented 3 years ago

Any solutions? Same problem here.

kthohr commented 3 years ago

Missing/undefined references to functions like dgemm_ implies that you have not linked to a BLAS/Lapack library.