简体   繁体   中英

Error information in the compiling of c++ with armadillo library

A beginner to armadillo library and have two problems with it. The first question is about the link of armadillo and c++. I installed armadillo by following the instructions in the package and the location is /usr/include/ , I could successfully run the code:

#include <iostream>
#include "/usr/include/armadillo"

using namespace std;

int main()
{
    arma::mat a = arma::randu<arma::mat>(3, 3);
    cout << a << endl;    
    return 0;
}

but if I want to define a function, for example, the inverse of the matrix (there is a function I can call from the library but I just want to do a test).

#include <iostream>
#include "/usr/include/armadillo"

using namespace std;

arma::mat Inverse( arma::mat A){
    return arma::inv(A);
}

int main()
{
    arma::mat a = arma::randu<arma::mat>(3, 3);
    arma::mat inv_a = Inverse(a);
    cout << inv_a << endl;

    return 0;
}

then the program failed with three error messages.

Undefined symbols for architecture x86_64:
  "_wrapper_dgetrf_", referenced from:
      void arma::lapack::getrf<double>(int*, int*, double*, int*, int*, int*) in main.o
  "_wrapper_dgetri_", referenced from:
      void arma::lapack::getri<double>(int*, double*, int*, int*, double*, int*, int*) in main.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

I checked by google and have tried some advices, like: " In miscellaneous MAC OS X linkers, I had to put "-01 -larmadillo" AND I had to deactivate the shared library settings!" , to be honest, I can not find the miscellaneous option and deactivate the shared library settings as i am not familiar with Xcode. Then I followed install MacPorts and the library is installed to the folder /usr/local/include/ , and I tried again, the first program is alright but the second program still has three errors, could anyone help me with this?

The second question would be the use of lapack when I am using armadillo in the same program, as I know armadillo is based on lapack, then if I declared the library armadillo , do I need to declare lapacke.h . Why do I ask this questions is that when I declared RcppArmadillo and lapacke.h , an error exists:

This file includes at least one deprecated or antiquated header. Please consider using of the 32 header found in section 17.4.1.2 of the C++ standard. Example include substituting the <X> header for the <X.h> hear for C++ includes, or <iostream> instead of the deprecated header <iostream.h>. To disable this warning use -Wno-deprecated. [-W#warnings]
Line 11763 conflicting type for 'cgetrf'
Line 11765 conflicting type for 'zgetrg_'
...

I had the same problem, but eventually I solved it. I didn't installed armadillo for my own purpose, but provided absolute path to include and library directories. Also, in a README there is a note that if you're on Mac then you should use Accelerate framework like this "-framework Accelerate". So after doing this all linker errors were gone.

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