user3813057
user3813057

Reputation: 911

Cannot compile example code in libpca

I'm trying to install the libpca package. I've already have Armadillo set up.

The libpca package is unzipped to /my/dir/. And I set the CPLUS_INCLUDE_PATH and other variables to the place Armadillo installed. (export CPLUS_INCLUDE_PATH=/my/dir/arma_install/include/:$CPLUS_INCLUDE_PATH)

I run the following command to install libpca:

/my/dir/libpca-1.3.3$  ./configure --prefix=/my/dir/libpca-1.3.3
/my/dir/libpca-1.3.3$  make

which has warnings but no error. And the command:

/my/dir/libpca-1.3.3$  make install prefix=/my/dir/libpca-1.3.3

It seems good and no error is reported.

Then I try to compile and run the example file in /my/dir/libpca-1.3.3/examples/simple/pca_example.cpp. In dir examples, I run

/my/dir/libpca-1.3.3/examples$  make

It returns

make[1]: Nothing to be done for 'all'

make[1]: Nothing to be done for 'all-am'

And no new file is created. Then I cd into examples/simple, and run

/my/dir/libpca-1.3.3/examples/simple$  make

It returns:

make: Nothing to be done for 'all'

And no new file is created. Then I run

/my/dir/libpca-1.3.3/examples/simple$  make check

It returns the following errors:

The variables wrapper_dsyev_, wrapper_dgemv_, wrapper_dgemm_, etc. in the errors above, exist in the following binaries:

/my/dir/arma_install/lib64/libarmadillo.so.8.500.0
/my/dir/arma_downloaded/CMakeFiles/armadillo.dir/src/wrapper.cpp.o
/my/dir/arma_downloaded/CMakeFiles/CMakeRelink.dir/libarmadillo.so.8.500.0

After I export them into LD_LIBRARY_PATH, the same errors are still returned.

I think there should be something wrong with the include path, and environment variables. How do I solve it?

Moreover, if I need to write code in /my/dir/working_dir/, how can I set the path?

----------------------------------edited below--------------------

When I made the update described below, at step 3:

/my/dir/libpca-1.3.3$ LD_LIBRARY_PATH=/my/dir/arma_install/lib64 make check

It returns the following errors:

LD_LIBRARY_PATH=/my/dir/arma_install/lib64/ make check

Making check in src/lib

make[1]: Entering directory `/my/dir/libpca-1.3.3/src/lib'

make[1]: Leaving directory `/my/dir/libpca-1.3.3/src/lib'

Making check in test

make[1]: Entering directory `/my/dir/libpca-1.3.3/test'

make unittest

make[2]: Entering directory `/my/dir/libpca-1.3.3/test'

/bin/sh ../libtool --tag=CXX --mode=link g++ -I../src/lib
-pthread -O2 -o unittest main.o testcases.o test_pca.o test_utils.o ../src/lib/.libs/libpca.a -L/my/dir/source_scripts/lib64

libtool: link: g++ -I../src/lib -pthread -O2 -o unittest main.o testcases.o test_pca.o test_utils.o ../src/lib/.libs/libpca.a -L/my/dir/arma_install/lib64 -pthread

test_utils.o: In function `void arma::glue_times::apply, arma::Mat

(arma::Mat&, arma::Mat const&, arma::Mat const&, double)':

test_utils.cpp:(.text.hot._ZN4arma10glue_times5applyIdLb1ELb0ELb1ENS_3MatIdEES3_EEvRNS2_IT_EERKT3_RKT4_S4_[_ZN4arma10glue_times5applyIdLb1ELb0ELb1ENS_3MatIdEES3_EEvRNS2_IT_EERKT3_RKT4_S4_]+0x169): undefined reference to `wrapper_dgemm_'

test_utils.cpp:(.text.hot._ZN4arma10glue_times5applyIdLb1ELb0ELb1ENS_3MatIdEES3_EEvRNS2_IT_EERKT3_RKT4_S4_[_ZN4arma10glue_times5applyIdLb1ELb0ELb1ENS_3MatIdEES3_EEvRNS2_IT_EERKT3_RKT4_S4_]+0x363): undefined reference to `wrapper_dgemv_'

test_utils.cpp:(.text.hot._ZN4arma10glue_times5applyIdLb1ELb0ELb1ENS_3MatIdEES3_EEvRNS2_IT_EERKT3_RKT4_S4_[_ZN4arma10glue_times5applyIdLb1ELb0ELb1ENS_3MatIdEES3_EEvRNS2_IT_EERKT3_RKT4_S4_]+0x45c): undefined reference to `wrapper_dsyrk_'

../src/lib/.libs/libpca.a(pca.o): In function `stats::pca::bootstrap_eigenvalues_()':

pca.cpp:(.text+0x454d): undefined reference to `wrapper_dsyev_'

pca.cpp:(.text+0x4953): undefined reference to `wrapper_dsyevd_'

../src/lib/.libs/libpca.a(pca.o): In function `bool arma::auxlib::eig_sym_dc

(arma::Col&, arma::Mat&, arma::Base > const&)':

pca.cpp:(.text._ZN4arma6auxlib10eig_sym_dcIdNS_3MatIdEEEEbRNS_3ColIT_EERNS2_IS5_EERKNS_4BaseIS5_T0_EE[_ZN4arma6auxlib10eig_sym_dcIdNS_3MatIdEEEEbRNS_3ColIT_EERNS2_IS5_EERKNS_4BaseIS5_T0_EE]+0x13a): undefined reference to `wrapper_dsyevd_'

../src/lib/.libs/libpca.a(pca.o): In function `bool arma::eig_sym

(arma::Col::pod_type>&, arma::Mat::elem_type>&, arma::Base::elem_type, arma::Mat > const&, char const*, arma::arma_blas_type_only::elem_type>::result const*)':

pca.cpp:(.text._ZN4arma7eig_symINS_3MatIdEEEEbRNS_3ColINT_8pod_typeEEERNS1_INS4_9elem_typeEEERKNS_4BaseIS8_S4_EEPKcPKNS_19arma_blas_type_onlyIS8_E6resultE[_ZN4arma7eig_symINS_3MatIdEEEEbRNS_3ColINT_8pod_typeEEERNS1_INS4_9elem_typeEEERKNS_4BaseIS8_S4_EEPKcPKNS_19arma_blas_type_onlyIS8_E6resultE]+0x1a0): undefined reference to `wrapper_dsyev_'

../src/lib/.libs/libpca.a(pca.o): In function `double arma::auxlib::det_lapack(arma::Mat const&, bool)':

pca.cpp:(.text._ZN4arma6auxlib10det_lapackIdEET_RKNS_3MatIS2_EEb[_ZN4arma6auxlib10det_lapackIdEET_RKNS_3MatIS2_EEb]+0x117): undefined reference to `wrapper_dgetrf_'

../src/lib/.libs/libpca.a(pca.o): In function `void arma::gemv::apply_blas_type >(double*, arma::Mat const&, double const*, double, double)':

pca.cpp:(.text._ZN4arma4gemvILb1ELb0ELb0EE15apply_blas_typeIdNS_3MatIdEEEEvPT_RKT0_PKS5_S5_S5_[_ZN4arma4gemvILb1ELb0ELb0EE15apply_blas_typeIdNS_3MatIdEEEEvPT_RKT0_PKS5_S5_S5_]+0x86): undefined reference to `wrapper_dgemv_'

../src/lib/.libs/libpca.a(pca.o): In function `void arma::gemv::apply_blas_type >(double*, arma::Mat const&, double const*, double, double)':

pca.cpp:(.text._ZN4arma4gemvILb0ELb0ELb0EE15apply_blas_typeIdNS_3MatIdEEEEvPT_RKT0_PKS5_S5_S5_[_ZN4arma4gemvILb0ELb0ELb0EE15apply_blas_typeIdNS_3MatIdEEEEvPT_RKT0_PKS5_S5_S5_]+0x86): undefined reference to `wrapper_dgemv_'

../src/lib/.libs/libpca.a(pca.o): In function `void arma::glue_times::apply, arma::Mat >(arma::Mat&, arma::Mat const&, arma::Mat const&, double)':

pca.cpp:(.text.hot._ZN4arma10glue_times5applyIdLb0ELb0ELb0ENS_3MatIdEES3_EEvRNS2_IT_EERKT3_RKT4_S4_[_ZN4arma10glue_times5applyIdLb0ELb0ELb0ENS_3MatIdEES3_EEvRNS2_IT_EERKT3_RKT4_S4_]+0x129): undefined reference to `wrapper_dgemm_'

pca.cpp:(.text.hot._ZN4arma10glue_times5applyIdLb0ELb0ELb0ENS_3MatIdEES3_EEvRNS2_IT_EERKT3_RKT4_S4_[_ZN4arma10glue_times5applyIdLb0ELb0ELb0ENS_3MatIdEES3_EEvRNS2_IT_EERKT3_RKT4_S4_]+0x334): undefined reference to `wrapper_dgemv_'

../src/lib/.libs/libpca.a(pca.o): In function `void arma::glue_times::apply, arma::Mat >(arma::Mat&, arma::Mat const&, arma::Mat const&, double)':

pca.cpp:(.text.hot._ZN4arma10glue_times5applyIdLb0ELb1ELb0ENS_3MatIdEES3_EEvRNS2_IT_EERKT3_RKT4_S4_[_ZN4arma10glue_times5applyIdLb0ELb1ELb0ENS_3MatIdEES3_EEvRNS2_IT_EERKT3_RKT4_S4_]+0x14a): undefined reference to `wrapper_dgemm_'

pca.cpp:(.text.hot._ZN4arma10glue_times5applyIdLb0ELb1ELb0ENS_3MatIdEES3_EEvRNS2_IT_EERKT3_RKT4_S4_[_ZN4arma10glue_times5applyIdLb0ELb1ELb0ENS_3MatIdEES3_EEvRNS2_IT_EERKT3_RKT4_S4_]+0x33c): undefined reference to `wrapper_dsyrk_'

../src/lib/.libs/libpca.a(utils.o): In function `stats::utils::compute_column_rms(arma::Mat const&)':

utils.cpp:(.text+0xe95): undefined reference to `wrapper_ddot_'

../src/lib/.libs/libpca.a(utils.o): In function `void arma::glue_times::apply, arma::Mat >(arma::Mat&, arma::Mat const&, arma::Mat const&, double)':

utils.cpp:(.text.hot._ZN4arma10glue_times5applyIdLb1ELb0ELb0ENS_3MatIdEES3_EEvRNS2_IT_EERKT3_RKT4_S4_[_ZN4arma10glue_times5applyIdLb1ELb0ELb0ENS_3MatIdEES3_EEvRNS2_IT_EERKT3_RKT4_S4_]+0x353): undefined reference to `wrapper_dgemm_'

utils.cpp:(.text.hot._ZN4arma10glue_times5applyIdLb1ELb0ELb0ENS_3MatIdEES3_EEvRNS2_IT_EERKT3_RKT4_S4_[_ZN4arma10glue_times5applyIdLb1ELb0ELb0ENS_3MatIdEES3_EEvRNS2_IT_EERKT3_RKT4_S4_]+0x8a4): undefined reference to `wrapper_dgemv_'

utils.cpp:(.text.hot._ZN4arma10glue_times5applyIdLb1ELb0ELb0ENS_3MatIdEES3_EEvRNS2_IT_EERKT3_RKT4_S4_[_ZN4arma10glue_times5applyIdLb1ELb0ELb0ENS_3MatIdEES3_EEvRNS2_IT_EERKT3_RKT4_S4_]+0x9ab): undefined reference to `wrapper_dsyrk_'

collect2: error: ld returned 1 exit status

make[2]: *** [unittest] Error 1

make[2]: Leaving directory `/my/dir/libpca-1.3.3/test'

make[1]: *** [check-am] Error 2

make[1]: Leaving directory `/my/dir/libpca-1.3.3/test'

make: *** [check-recursive] Error 1

What should I do next?

Upvotes: 1

Views: 209

Answers (1)

Christian Blume
Christian Blume

Reputation: 308

You need to tell the linker of the location of your armadillo library. You can achieve this in two ways:

  1. Through environment variable: export LIBRARY_PATH=/arma/lib:$LIBRARY_PATH
  2. Passing armadillo include and library path to configure directly: ./configure --with-armadillo-incdir=/arma/include --with-armadillo-libdir=/arma/lib

I would recommend using option 2 as it prevents settings up extra environment variables which may pollute, well, your environment.

Note that --prefix denotes the directory in which libpca is being installed to. This should be different from the source directory!

After configure you can run make, make check, and make install. For make check to succeed the linux library loader needs to know the location of the armadillo shared library. So one option is to run like so: LD_LIBRARY_PATH=/arma/lib make check

To summarize the commands you need to run:

  1. ./configure --prefix=/libpca/install --with-armadillo-incdir=/arma/include --with-armadillo-libdir=/arma/lib
  2. make
  3. LD_LIBRARY_PATH=/arma/lib make check
  4. make install

Obviously, you need to adjust the paths to your situation.

Caveat: On some platforms you need to explicitly link with lapack and blas. So if you run into further linker errors then try configuring like this: LIBS='-llapack -lblas' ./configure --prefix=/libpca/install --with-armadillo-incdir=/arma/include --with-armadillo-libdir=/arma/lib

Upvotes: 1

Related Questions