简体   繁体   中英

Error linking against Armadillo using PGI compiler

I want to accelerate a portion of my code using OpenACC to allow it run on GPUs ,but the most of my code uses Armadillo library for the linear algebra. The easiest way that I found to accelerate the code relies on the PGI set of compilers, but it seems that is not so easy to enable the PGI compiler to link against Armadillo. I tried to follow the recommendation here but it does not work for me in the case of the simplified example in the post:

#include <iostream> 
#include <armadillo> 

using namespace std; 
using namespace arma; 

int main(int argc, char** argv) 
  { 
  mat A = randu<mat>(4,5); 
  mat B = randu<mat>(4,5); 

  cout << A*B.t() << endl; 

#if defined(__GNUG__) 
cout << "I say I'm gcc!" << endl; 
#endif 

#if defined(__PGI) 
cout << "I say I'm PGI!" << endl; 
#endif 
  return 0; 
  } 

It is supposed to compiles using pgc++ -U__GNUG__ -o test.x test.cpp . However, I get lots of errors and warnings. I don't know what is going wrong with this, any suggestion will be very appreciated.

The Error message that I get is:

/tmp/pgc++RnBhbTnyXPYy.o: En la función `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*)':
test.cpp:(.gnu.linkonce.t._ZN4arma4blas4gemvIdEEvPKcPKiS5_PKT_S8_S5_S8_S5_S8_PS6_S5_+0x7c): referencia a `wrapper_sgemv_' sin definir
test.cpp:(.gnu.linkonce.t._ZN4arma4blas4gemvIdEEvPKcPKiS5_PKT_S8_S5_S8_S5_S8_PS6_S5_+0xcd): referencia a `wrapper_dgemv_' sin definir
test.cpp:(.gnu.linkonce.t._ZN4arma4blas4gemvIdEEvPKcPKiS5_PKT_S8_S5_S8_S5_S8_PS6_S5_+0x11e): referencia a `wrapper_cgemv_' sin definir
test.cpp:(.gnu.linkonce.t._ZN4arma4blas4gemvIdEEvPKcPKiS5_PKT_S8_S5_S8_S5_S8_PS6_S5_+0x16c): referencia a `wrapper_zgemv_' sin definir
/tmp/pgc++RnBhbTnyXPYy.o: En la función `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*)':
test.cpp:(.gnu.linkonce.t._ZN4arma4blas4gemmIdEEvPKcS3_PKiS5_S5_PKT_S8_S5_S8_S5_S8_PS6_S5_+0x8e): referencia a `wrapper_sgemm_' sin definir
test.cpp:(.gnu.linkonce.t._ZN4arma4blas4gemmIdEEvPKcS3_PKiS5_S5_PKT_S8_S5_S8_S5_S8_PS6_S5_+0xf1): referencia a `wrapper_dgemm_' sin definir
test.cpp:(.gnu.linkonce.t._ZN4arma4blas4gemmIdEEvPKcS3_PKiS5_S5_PKT_S8_S5_S8_S5_S8_PS6_S5_+0x154): referencia a `wrapper_cgemm_' sin definir
test.cpp:(.gnu.linkonce.t._ZN4arma4blas4gemmIdEEvPKcS3_PKiS5_S5_PKT_S8_S5_S8_S5_S8_PS6_S5_+0x1b4): referencia a `wrapper_zgemm_' sin definir
/tmp/pgc++RnBhbTnyXPYy.o: En la función `double arma::blas::dot<double>(unsigned int, double const*, double const*)':
test.cpp:(.gnu.linkonce.t._ZN4arma4blas3dotIdEET_jPKS2_S4_+0x34): referencia a `wrapper_sdot_' sin definir
test.cpp:(.gnu.linkonce.t._ZN4arma4blas3dotIdEET_jPKS2_S4_+0x61): referencia a `wrapper_ddot_' sin definir
/tmp/pgc++RnBhbTnyXPYy.o: En la función `void arma::blas::syrk<double>(char const*, char const*, int const*, int const*, double const*, double const*, int const*, double const*, double*, int const*)':
test.cpp:(.gnu.linkonce.t._ZN4arma4blas4syrkIdEEvPKcS3_PKiS5_PKT_S8_S5_S8_PS6_S5_+0x73): referencia a `wrapper_ssyrk_' sin definir
test.cpp:(.gnu.linkonce.t._ZN4arma4blas4syrkIdEEvPKcS3_PKiS5_PKT_S8_S5_S8_PS6_S5_+0xbb): referencia a `wrapper_dsyrk_' sin definir
/tmp/pgc++RnBhbTnyXPYy.o: En la función `void arma::lapack::gesv<double>(int*, int*, double*, int*, int*, double*, int*, int*)':
test.cpp:(.gnu.linkonce.t._ZN4arma6lapack4gesvIdEEvPiS2_PT_S2_S2_S4_S2_S2_+0x61): referencia a `wrapper_sgesv_' sin definir
test.cpp:(.gnu.linkonce.t._ZN4arma6lapack4gesvIdEEvPiS2_PT_S2_S2_S4_S2_S2_+0x99): referencia a `wrapper_dgesv_' sin definir
test.cpp:(.gnu.linkonce.t._ZN4arma6lapack4gesvIdEEvPiS2_PT_S2_S2_S4_S2_S2_+0xcc): referencia a `wrapper_cgesv_' sin definir
test.cpp:(.gnu.linkonce.t._ZN4arma6lapack4gesvIdEEvPiS2_PT_S2_S2_S4_S2_S2_+0xff): referencia a `wrapper_zgesv_' sin definir
/tmp/pgc++RnBhbTnyXPYy.o: En la función `void arma::lapack::gels<double>(char*, int*, int*, int*, double*, int*, double*, int*, double*, int*, int*)':
test.cpp:(.gnu.linkonce.t._ZN4arma6lapack4gelsIdEEvPcPiS3_S3_PT_S3_S5_S3_S5_S3_S3_+0x7c): referencia a `wrapper_sgels_' sin definir
test.cpp:(.gnu.linkonce.t._ZN4arma6lapack4gelsIdEEvPcPiS3_S3_PT_S3_S5_S3_S5_S3_S3_+0xcd): referencia a `wrapper_dgels_' sin definir
test.cpp:(.gnu.linkonce.t._ZN4arma6lapack4gelsIdEEvPcPiS3_S3_PT_S3_S5_S3_S5_S3_S3_+0x11e): referencia a `wrapper_cgels_' sin definir
test.cpp:(.gnu.linkonce.t._ZN4arma6lapack4gelsIdEEvPcPiS3_S3_PT_S3_S5_S3_S5_S3_S3_+0x16c): referencia a `wrapper_zgels_' sin definir

The undefined reference messages here are linker errors , which means that the linker couldn't find anywhere the implementation (the compiled code) for some functions used in your program.

Third-party functions are usually provided in the form of some library-file installed on your system. For each such additional library you use, an additional option of the form -lLIBRARY_NAME is to be included in the build command.

The most likely problem here is that you need to add such an option to your build command: -larmadillo .

In case this doesn't work (if the Armadillo library-files were not installed in the usual library directories), you may want to read the Armadillo FAQ for other possible solutions.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM