简体   繁体   中英

How to solve the compiling problems when I use armadillo library'

I'm new in C++ and I tried to use Armadillo to find the eigenvalues of a symmetrical matrix (eig_sym is the function's name). I used 'g++ -std=c++14 main.cpp -o app -O2 -larmadillo -llapack -lbas' and the exit was

error: 'eig_sym' was not declared in this scope eig_sym( eigval, A ); ^ eigval_sym.cpp:44:21: note: suggested alternative: In file included from /usr/include/armadillo:443:0, from main.cpp:6: /usr/include/armadillo_bits/fn_eig_sym.hpp:118:1: note: 'arma::eig_sym'

,but in the main.cpp file I wrote #include. When is the failure? Library path is not found maybe?

just #include <armadillo> is enough to get all functionality from the armadillo library, but do note that everything in armadillo is in the arma namespace . Therefore, you need to either add using namespace arma; in your cpp file or prepend all functions and classes in armadillo with arma:: . That is, use arma::eig_sym instead of just eig_sym or add the using directive and continue to write just eig_sym .

This is the same thing you need to do with the standard library, which is in the namespace std . You need to write std::cout and not just cout , unless you add using namespace std; .

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