Related
I am trying to convert an object of type ODE_vector to an armadillo vec such that the new object will inherit the linear algebraic functionality of the armadillo library. As a simple example of the problem I am having this is a demonstration using a C++ array:
#include <iostream>
#include <random>
#include <armadillo>
using namespace std;
using namespace arma;
int main() {
double b1 = 0.2;
double b2 = 0.1;
const double state[2] = {b1, b2};
rowvec B(&state[0], 2);
cout << B << endl;
mat A(2,2); A.fill(0.2); A.diag().ones();
cout << A << endl;
cout << B(0) * A(0,0) << endl; // x
return 0;
}
The data contained in b1 and b2 is saved in the elements of B so that running this script returns the following:
0.2000
0.1000
1.0000 0.2000
0.2000 1.0000
0.2
HOWEVER, if I replace line x above with
cout << B * A << endl;
I get errors suggesting B has not inherited the standard armadillo linear algebra functionality:
[ 50%] Building CXX object CMakeFiles/untitled.dir/main.cpp.o
[100%] Linking CXX executable untitled
CMakeFiles/untitled.dir/main.cpp.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*)':
/usr/include/armadillo_bits/wrapper_blas.hpp:36: undefined reference to `wrapper_dgemv_'
CMakeFiles/untitled.dir/main.cpp.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*)':
/usr/include/armadillo_bits/wrapper_blas.hpp:71: undefined reference to `wrapper_dgemm_'
collect2: error: ld returned 1 exit status
CMakeFiles/untitled.dir/build.make:94: recipe for target 'untitled' failed
make[3]: *** [untitled] Error 1
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/untitled.dir/all' failed
make[2]: *** [CMakeFiles/untitled.dir/all] Error 2
CMakeFiles/Makefile2:79: recipe for target 'CMakeFiles/untitled.dir/rule' failed
make[1]: *** [CMakeFiles/untitled.dir/rule] Error 2
Makefile:118: recipe for target 'untitled' failed
make: *** [untitled] Error 2
Can anyone explain how to properly use the advanced constructors (arma documentation) to get this working?
Thanks
You need to have the right format in the multiplication. Type B is a 2x1 and A is 2x2. Change to
mat B(&state[0], 1,2);
or
rowvec B(&state[0], 2);
I'm trying to compile the first example presented in CGAL's Quadratic Programming document here. I'm using Debian Jessie and installed CGAL via sudo apt-get libcgal-dev and verified that it's present in /usr/include, along with a few of its dependencies, e.g. boost, gmpxx.h, mpfr.h. Per gmp's document here, I try to compile with: g++ first_qp.cpp -lmpfr -lgmp
It appears I get several linker errors below. Any help is appreciated, thanks!
/tmp/ccPeDUda.o: In function `CGAL::Algebraic_structure_traits<CGAL::Gmpz>::Integral_division::operator()(CGAL::Gmpz const&, CGAL::Gmpz const&) const':
first_qp.cpp:(.text._ZNK4CGAL26Algebraic_structure_traitsINS_4GmpzEE17Integral_divisionclERKS1_S5_[_ZNK4CGAL26Algebraic_structure_traitsINS_4GmpzEE17Integral_divisionclERKS1_S5_]+0xac): undefined reference to `CGAL::postcondition_fail(char const*, char const*, int, char const*)'
/tmp/ccPeDUda.o: In function `CGAL::Handle_for<CGAL::Gmpz_rep, std::allocator<CGAL::Gmpz_rep> >::Handle_for(CGAL::Handle_for<CGAL::Gmpz_rep, std::allocator<CGAL::Gmpz_rep> > const&)':
first_qp.cpp:(.text._ZN4CGAL10Handle_forINS_8Gmpz_repESaIS1_EEC2ERKS3_[_ZN4CGAL10Handle_forINS_8Gmpz_repESaIS1_EEC5ERKS3_]+0x50): undefined reference to `CGAL::assertion_fail(char const*, char const*, int, char const*)'
/tmp/ccPeDUda.o: In function `CGAL::Quadratic_program<int>::Quadratic_program(CGAL::Sign, bool, int, bool, int)':
first_qp.cpp:(.text._ZN4CGAL17Quadratic_programIiEC2ENS_4SignEbibi[_ZN4CGAL17Quadratic_programIiEC5ENS_4SignEbibi]+0x190): undefined reference to `CGAL::assertion_fail(char const*, char const*, int, char const*)'
/tmp/ccPeDUda.o: In function `CGAL::Quadratic_program<int>::set_a(int, int, int const&)':
first_qp.cpp:(.text._ZN4CGAL17Quadratic_programIiE5set_aEiiRKi[_ZN4CGAL17Quadratic_programIiE5set_aEiiRKi]+0x41): undefined reference to `CGAL::assertion_fail(char const*, char const*, int, char const*)'
first_qp.cpp:(.text._ZN4CGAL17Quadratic_programIiE5set_aEiiRKi[_ZN4CGAL17Quadratic_programIiE5set_aEiiRKi]+0x70): undefined reference to `CGAL::assertion_fail(char const*, char const*, int, char const*)'
/tmp/ccPeDUda.o: In function `CGAL::Quadratic_program<int>::set_b(int, int const&)':
first_qp.cpp:(.text._ZN4CGAL17Quadratic_programIiE5set_bEiRKi[_ZN4CGAL17Quadratic_programIiE5set_bEiRKi]+0x3e): undefined reference to `CGAL::assertion_fail(char const*, char const*, int, char const*)'
/tmp/ccPeDUda.o:first_qp.cpp:(.text._ZN4CGAL17Quadratic_programIiE5set_uEibRKi[_ZN4CGAL17Quadratic_programIiE5set_uEibRKi]+0x43): more undefined references to `CGAL::assertion_fail(char const*, char const*, int, char const*)' follow
/tmp/ccPeDUda.o: In function `CGAL::QP_solver<CGAL::Quadratic_program<int>, CGAL::Gmpz, CGAL::QP_solver_impl::QP_tags<CGAL::Boolean_tag<false>, CGAL::Boolean_tag<false> > >::set_pricing_strategy(CGAL::Quadratic_program_pricing_strategy)':
first_qp.cpp:(.text._ZN4CGAL9QP_solverINS_17Quadratic_programIiEENS_4GmpzENS_14QP_solver_impl7QP_tagsINS_11Boolean_tagILb0EEES7_EEE20set_pricing_strategyENS_34Quadratic_program_pricing_strategyE[_ZN4CGAL9QP_solverINS_17Quadratic_programIiEENS_4GmpzENS_14QP_solver_impl7QP_tagsINS_11Boolean_tagILb0EEES7_EEE20set_pricing_strategyENS_34Quadratic_program_pricing_strategyE]+0xee): undefined reference to `CGAL::default_random'
first_qp.cpp:(.text._ZN4CGAL9QP_solverINS_17Quadratic_programIiEENS_4GmpzENS_14QP_solver_impl7QP_tagsINS_11Boolean_tagILb0EEES7_EEE20set_pricing_strategyENS_34Quadratic_program_pricing_strategyE[_ZN4CGAL9QP_solverINS_17Quadratic_programIiEENS_4GmpzENS_14QP_solver_impl7QP_tagsINS_11Boolean_tagILb0EEES7_EEE20set_pricing_strategyENS_34Quadratic_program_pricing_strategyE]+0x140): undefined reference to `CGAL::default_random'
first_qp.cpp:(.text._ZN4CGAL9QP_solverINS_17Quadratic_programIiEENS_4GmpzENS_14QP_solver_impl7QP_tagsINS_11Boolean_tagILb0EEES7_EEE20set_pricing_strategyENS_34Quadratic_program_pricing_strategyE[_ZN4CGAL9QP_solverINS_17Quadratic_programIiEENS_4GmpzENS_14QP_solver_impl7QP_tagsINS_11Boolean_tagILb0EEES7_EEE20set_pricing_strategyENS_34Quadratic_program_pricing_strategyE]+0x1d2): undefined reference to `CGAL::assertion_fail(char const*, char const*, int, char const*)'
/tmp/ccPeDUda.o: In function `CGAL::QP_solver<CGAL::Quadratic_program<int>, CGAL::Gmpz, CGAL::QP_solver_impl::QP_tags<CGAL::Boolean_tag<false>, CGAL::Boolean_tag<false> > >::set(CGAL::Quadratic_program<int> const&)':
first_qp.cpp:(.text._ZN4CGAL9QP_solverINS_17Quadratic_programIiEENS_4GmpzENS_14QP_solver_impl7QP_tagsINS_11Boolean_tagILb0EEES7_EEE3setERKS2_[_ZN4CGAL9QP_solverINS_17Quadratic_programIiEENS_4GmpzENS_14QP_solver_impl7QP_tagsINS_11Boolean_tagILb0EEES7_EEE3setERKS2_]+0x55): undefined reference to `CGAL::assertion_fail(char const*, char const*, int, char const*)'
first_qp.cpp:(.text._ZN4CGAL9QP_solverINS_17Quadratic_programIiEENS_4GmpzENS_14QP_solver_impl7QP_tagsINS_11Boolean_tagILb0EEES7_EEE3setERKS2_[_ZN4CGAL9QP_solverINS_17Quadratic_programIiEENS_4GmpzENS_14QP_solver_impl7QP_tagsINS_11Boolean_tagILb0EEES7_EEE3setERKS2_]+0x90): undefined reference to `CGAL::assertion_fail(char const*, char const*, int, char const*)'
/tmp/ccPeDUda.o: In function `CGAL::QP_solver<CGAL::Quadratic_program<int>, CGAL::Gmpz, CGAL::QP_solver_impl::QP_tags<CGAL::Boolean_tag<false>, CGAL::Boolean_tag<false> > >::init()':
first_qp.cpp:(.text._ZN4CGAL9QP_solverINS_17Quadratic_programIiEENS_4GmpzENS_14QP_solver_impl7QP_tagsINS_11Boolean_tagILb0EEES7_EEE4initEv[_ZN4CGAL9QP_solverINS_17Quadratic_programIiEENS_4GmpzENS_14QP_solver_impl7QP_tagsINS_11Boolean_tagILb0EEES7_EEE4initEv]+0x107): undefined reference to `CGAL::assertion_fail(char const*, char const*, int, char const*)'
/tmp/ccPeDUda.o: In function `CGAL::QP_solver<CGAL::Quadratic_program<int>, CGAL::Gmpz, CGAL::QP_solver_impl::QP_tags<CGAL::Boolean_tag<false>, CGAL::Boolean_tag<false> > >::solve()':
first_qp.cpp:(.text._ZN4CGAL9QP_solverINS_17Quadratic_programIiEENS_4GmpzENS_14QP_solver_impl7QP_tagsINS_11Boolean_tagILb0EEES7_EEE5solveEv[_ZN4CGAL9QP_solverINS_17Quadratic_programIiEENS_4GmpzENS_14QP_solver_impl7QP_tagsINS_11Boolean_tagILb0EEES7_EEE5solveEv]+0x40): undefined reference to `CGAL::assertion_fail(char const*, char const*, int, char const*)'
/tmp/ccPeDUda.o:first_qp.cpp:(.text._ZNK4CGAL17Quadratic_programIiE5get_rEv[_ZNK4CGAL17Quadratic_programIiE5get_rEv]+0x3f): more undefined references to `CGAL::assertion_fail(char const*, char const*, int, char const*)' follow
/tmp/ccPeDUda.o: In function `CGAL::Quotient<CGAL::Gmpz>::Quotient<CGAL::Gmpz, CGAL::Gmpz>(CGAL::Gmpz const&, CGAL::Gmpz const&)':
first_qp.cpp:(.text._ZN4CGAL8QuotientINS_4GmpzEEC2IS1_S1_EERKT_RKT0_[_ZN4CGAL8QuotientINS_4GmpzEEC5IS1_S1_EERKT_RKT0_]+0x88): undefined reference to `CGAL::precondition_fail(char const*, char const*, int, char const*)'
/tmp/ccPeDUda.o: In function `CGAL::Quadratic_program_solution<CGAL::Gmpz>::infeasibility_certificate_begin() const':
first_qp.cpp:(.text._ZNK4CGAL26Quadratic_program_solutionINS_4GmpzEE31infeasibility_certificate_beginEv[_ZNK4CGAL26Quadratic_program_solutionINS_4GmpzEE31infeasibility_certificate_beginEv]+0x42): undefined reference to `CGAL::assertion_fail(char const*, char const*, int, char const*)'
first_qp.cpp:(.text._ZNK4CGAL26Quadratic_program_solutionINS_4GmpzEE31infeasibility_certificate_beginEv[_ZNK4CGAL26Quadratic_program_solutionINS_4GmpzEE31infeasibility_certificate_beginEv]+0x7b): undefined reference to `CGAL::assertion_fail(char const*, char const*, int, char const*)'
/tmp/ccPeDUda.o: In function `CGAL::Quadratic_program_solution<CGAL::Gmpz>::unboundedness_certificate_begin() const':
first_qp.cpp:(.text._ZNK4CGAL26Quadratic_program_solutionINS_4GmpzEE31unboundedness_certificate_beginEv[_ZNK4CGAL26Quadratic_program_solutionINS_4GmpzEE31unboundedness_certificate_beginEv]+0x42): undefined reference to `CGAL::assertion_fail(char const*, char const*, int, char const*)'
first_qp.cpp:(.text._ZNK4CGAL26Quadratic_program_solutionINS_4GmpzEE31unboundedness_certificate_beginEv[_ZNK4CGAL26Quadratic_program_solutionINS_4GmpzEE31unboundedness_certificate_beginEv]+0x7b): undefined reference to `CGAL::assertion_fail(char const*, char const*, int, char const*)'
/tmp/ccPeDUda.o: In function `CGAL::QP_solver<CGAL::Quadratic_program<int>, CGAL::Gmpz, CGAL::QP_solver_impl::QP_tags<CGAL::Boolean_tag<false>, CGAL::Boolean_tag<false> > >::init_x_O_v_i()':
first_qp.cpp:(.text._ZN4CGAL9QP_solverINS_17Quadratic_programIiEENS_4GmpzENS_14QP_solver_impl7QP_tagsINS_11Boolean_tagILb0EEES7_EEE12init_x_O_v_iEv[_ZN4CGAL9QP_solverINS_17Quadratic_programIiEENS_4GmpzENS_14QP_solver_impl7QP_tagsINS_11Boolean_tagILb0EEES7_EEE12init_x_O_v_iEv]+0x1d5): undefined reference to `CGAL::assertion_fail(char const*, char const*, int, char const*)'
/tmp/ccPeDUda.o:first_qp.cpp:(.text._ZN4CGAL16QP_basis_inverseINS_4GmpzENS_11Boolean_tagILb0EEEE3setEiii[_ZN4CGAL16QP_basis_inverseINS_4GmpzENS_11Boolean_tagILb0EEEE3setEiii]+0x43): more undefined references to `CGAL::assertion_fail(char const*, char const*, int, char const*)' follow
/tmp/ccPeDUda.o: In function `CGAL::Map_with_default<std::map<unsigned long, CGAL::Sign, std::less<unsigned long>, std::allocator<std::pair<unsigned long const, CGAL::Sign> > > >::operator()(unsigned long) const':
first_qp.cpp:(.text._ZNK4CGAL16Map_with_defaultISt3mapImNS_4SignESt4lessImESaISt4pairIKmS2_EEEEclEm[_ZNK4CGAL16Map_with_defaultISt3mapImNS_4SignESt4lessImESaISt4pairIKmS2_EEEEclEm]+0x40): undefined reference to `CGAL::precondition_fail(char const*, char const*, int, char const*)'
/tmp/ccPeDUda.o: In function `CGAL::Map_with_default<std::map<unsigned long, int, std::less<unsigned long>, std::allocator<std::pair<unsigned long const, int> > > >::operator()(unsigned long) const':
first_qp.cpp:(.text._ZNK4CGAL16Map_with_defaultISt3mapImiSt4lessImESaISt4pairIKmiEEEEclEm[_ZNK4CGAL16Map_with_defaultISt3mapImiSt4lessImESaISt4pairIKmiEEEEclEm]+0x40): undefined reference to `CGAL::precondition_fail(char const*, char const*, int, char const*)'
/tmp/ccPeDUda.o: In function `CGAL::Map_with_default<std::map<unsigned long, bool, std::less<unsigned long>, std::allocator<std::pair<unsigned long const, bool> > > >::operator()(unsigned long) const':
first_qp.cpp:(.text._ZNK4CGAL16Map_with_defaultISt3mapImbSt4lessImESaISt4pairIKmbEEEEclEm[_ZNK4CGAL16Map_with_defaultISt3mapImbSt4lessImESaISt4pairIKmbEEEEclEm]+0x40): undefined reference to `CGAL::precondition_fail(char const*, char const*, int, char const*)'
/tmp/ccPeDUda.o: In function `CGAL::QP_basis_inverse<CGAL::Gmpz, CGAL::Boolean_tag<false> >::ensure_physical_row(unsigned int)':
first_qp.cpp:(.text._ZN4CGAL16QP_basis_inverseINS_4GmpzENS_11Boolean_tagILb0EEEE19ensure_physical_rowEj[_ZN4CGAL16QP_basis_inverseINS_4GmpzENS_11Boolean_tagILb0EEEE19ensure_physical_rowEj]+0x4f): undefined reference to `CGAL::assertion_fail(char const*, char const*, int, char const*)'
first_qp.cpp:(.text._ZN4CGAL16QP_basis_inverseINS_4GmpzENS_11Boolean_tagILb0EEEE19ensure_physical_rowEj[_ZN4CGAL16QP_basis_inverseINS_4GmpzENS_11Boolean_tagILb0EEEE19ensure_physical_rowEj]+0x102): undefined reference to `CGAL::assertion_fail(char const*, char const*, int, char const*)'
first_qp.cpp:(.text._ZN4CGAL16QP_basis_inverseINS_4GmpzENS_11Boolean_tagILb0EEEE19ensure_physical_rowEj[_ZN4CGAL16QP_basis_inverseINS_4GmpzENS_11Boolean_tagILb0EEEE19ensure_physical_rowEj]+0x198): undefined reference to `CGAL::assertion_fail(char const*, char const*, int, char const*)'
first_qp.cpp:(.text._ZN4CGAL16QP_basis_inverseINS_4GmpzENS_11Boolean_tagILb0EEEE19ensure_physical_rowEj[_ZN4CGAL16QP_basis_inverseINS_4GmpzENS_11Boolean_tagILb0EEEE19ensure_physical_rowEj]+0x239): undefined reference to `CGAL::assertion_fail(char const*, char const*, int, char const*)'
/tmp/ccPeDUda.o: In function `CGAL::QP_solver<CGAL::Quadratic_program<int>, CGAL::Gmpz, CGAL::QP_solver_impl::QP_tags<CGAL::Boolean_tag<false>, CGAL::Boolean_tag<false> > >::original_variable_value_under_bounds(int) const':
first_qp.cpp:(.text._ZNK4CGAL9QP_solverINS_17Quadratic_programIiEENS_4GmpzENS_14QP_solver_impl7QP_tagsINS_11Boolean_tagILb0EEES7_EEE36original_variable_value_under_boundsEi[_ZNK4CGAL9QP_solverINS_17Quadratic_programIiEENS_4GmpzENS_14QP_solver_impl7QP_tagsINS_11Boolean_tagILb0EEES7_EEE36original_variable_value_under_boundsEi]+0x6c): undefined reference to `CGAL::assertion_fail(char const*, char const*, int, char const*)'
/tmp/ccPeDUda.o:first_qp.cpp:(.text._ZNK4CGAL9QP_solverINS_17Quadratic_programIiEENS_4GmpzENS_14QP_solver_impl7QP_tagsINS_11Boolean_tagILb0EEES7_EEE36original_variable_value_under_boundsEi[_ZNK4CGAL9QP_solverINS_17Quadratic_programIiEENS_4GmpzENS_14QP_solver_impl7QP_tagsINS_11Boolean_tagILb0EEES7_EEE36original_variable_value_under_boundsEi]+0x163): more undefined references to `CGAL::assertion_fail(char const*, char const*, int, char const*)' follow
/tmp/ccPeDUda.o: In function `CGAL::Quotient<CGAL::Gmpz>::operator/=(CGAL::Quotient<CGAL::Gmpz> const&)':
first_qp.cpp:(.text._ZN4CGAL8QuotientINS_4GmpzEEdVERKS2_[_ZN4CGAL8QuotientINS_4GmpzEEdVERKS2_]+0x4d): undefined reference to `CGAL::precondition_fail(char const*, char const*, int, char const*)'
/tmp/ccPeDUda.o: In function `CGAL::QP_solver<CGAL::Quadratic_program<int>, CGAL::Gmpz, CGAL::QP_solver_impl::QP_tags<CGAL::Boolean_tag<false>, CGAL::Boolean_tag<false> > >::replace_variable(CGAL::Boolean_tag<false>)':
first_qp.cpp:(.text._ZN4CGAL9QP_solverINS_17Quadratic_programIiEENS_4GmpzENS_14QP_solver_impl7QP_tagsINS_11Boolean_tagILb0EEES7_EEE16replace_variableES7_[_ZN4CGAL9QP_solverINS_17Quadratic_programIiEENS_4GmpzENS_14QP_solver_impl7QP_tagsINS_11Boolean_tagILb0EEES7_EEE16replace_variableES7_]+0x18c): undefined reference to `CGAL::assertion_fail(char const*, char const*, int, char const*)'
/tmp/ccPeDUda.o: In function `CGAL::QP_solver<CGAL::Quadratic_program<int>, CGAL::Gmpz, CGAL::QP_solver_impl::QP_tags<CGAL::Boolean_tag<false>, CGAL::Boolean_tag<false> > >::z_replace_variable_slack_by_original()':
first_qp.cpp:(.text._ZN4CGAL9QP_solverINS_17Quadratic_programIiEENS_4GmpzENS_14QP_solver_impl7QP_tagsINS_11Boolean_tagILb0EEES7_EEE36z_replace_variable_slack_by_originalEv[_ZN4CGAL9QP_solverINS_17Quadratic_programIiEENS_4GmpzENS_14QP_solver_impl7QP_tagsINS_11Boolean_tagILb0EEES7_EEE36z_replace_variable_slack_by_originalEv]+0xeb): undefined reference to `CGAL::assertion_fail(char const*, char const*, int, char const*)'
/tmp/ccPeDUda.o: In function `void CGAL::QP_basis_inverse<CGAL::Gmpz, CGAL::Boolean_tag<false> >::enter_original_leave_original<__gnu_cxx::__normal_iterator<CGAL::Gmpz*, std::vector<CGAL::Gmpz, std::allocator<CGAL::Gmpz> > > >(__gnu_cxx::__normal_iterator<CGAL::Gmpz*, std::vector<CGAL::Gmpz, std::allocator<CGAL::Gmpz> > >, unsigned int)':
first_qp.cpp:(.text._ZN4CGAL16QP_basis_inverseINS_4GmpzENS_11Boolean_tagILb0EEEE29enter_original_leave_originalIN9__gnu_cxx17__normal_iteratorIPS1_St6vectorIS1_SaIS1_EEEEEEvT_j[_ZN4CGAL16QP_basis_inverseINS_4GmpzENS_11Boolean_tagILb0EEEE29enter_original_leave_originalIN9__gnu_cxx17__normal_iteratorIPS1_St6vectorIS1_SaIS1_EEEEEEvT_j]+0x6d): undefined reference to `CGAL::assertion_fail(char const*, char const*, int, char const*)'
first_qp.cpp:(.text._ZN4CGAL16QP_basis_inverseINS_4GmpzENS_11Boolean_tagILb0EEEE29enter_original_leave_originalIN9__gnu_cxx17__normal_iteratorIPS1_St6vectorIS1_SaIS1_EEEEEEvT_j[_ZN4CGAL16QP_basis_inverseINS_4GmpzENS_11Boolean_tagILb0EEEE29enter_original_leave_originalIN9__gnu_cxx17__normal_iteratorIPS1_St6vectorIS1_SaIS1_EEEEEEvT_j]+0xa7): undefined reference to `CGAL::assertion_fail(char const*, char const*, int, char const*)'
first_qp.cpp:(.text._ZN4CGAL16QP_basis_inverseINS_4GmpzENS_11Boolean_tagILb0EEEE29enter_original_leave_originalIN9__gnu_cxx17__normal_iteratorIPS1_St6vectorIS1_SaIS1_EEEEEEvT_j[_ZN4CGAL16QP_basis_inverseINS_4GmpzENS_11Boolean_tagILb0EEEE29enter_original_leave_originalIN9__gnu_cxx17__normal_iteratorIPS1_St6vectorIS1_SaIS1_EEEEEEvT_j]+0x49c): undefined reference to `CGAL::assertion_fail(char const*, char const*, int, char const*)'
/tmp/ccPeDUda.o:first_qp.cpp:(.text._ZN4CGAL16QP_basis_inverseINS_4GmpzENS_11Boolean_tagILb0EEEE26enter_original_leave_slackIN9__gnu_cxx17__normal_iteratorIPS1_St6vectorIS1_SaIS1_EEEESC_EEvT_T0_[_ZN4CGAL16QP_basis_inverseINS_4GmpzENS_11Boolean_tagILb0EEEE26enter_original_leave_slackIN9__gnu_cxx17__normal_iteratorIPS1_St6vectorIS1_SaIS1_EEEESC_EEvT_T0_]+0x6e): more undefined references to `CGAL::assertion_fail(char const*, char const*, int, char const*)' follow
/tmp/ccPeDUda.o: In function `CGAL::QP__partial_base<CGAL::Quadratic_program<int>, CGAL::Gmpz, CGAL::QP_solver_impl::QP_tags<CGAL::Boolean_tag<false>, CGAL::Boolean_tag<false> > >::activating(__gnu_cxx::__normal_iterator<int const*, std::vector<int, std::allocator<int> > >&)':
first_qp.cpp:(.text._ZN4CGAL16QP__partial_baseINS_17Quadratic_programIiEENS_4GmpzENS_14QP_solver_impl7QP_tagsINS_11Boolean_tagILb0EEES7_EEE10activatingERN9__gnu_cxx17__normal_iteratorIPKiSt6vectorIiSaIiEEEE[_ZN4CGAL16QP__partial_baseINS_17Quadratic_programIiEENS_4GmpzENS_14QP_solver_impl7QP_tagsINS_11Boolean_tagILb0EEES7_EEE10activatingERN9__gnu_cxx17__normal_iteratorIPKiSt6vectorIiSaIiEEEE]+0xa0): undefined reference to `CGAL::precondition_fail(char const*, char const*, int, char const*)'
/tmp/ccPeDUda.o: In function `CGAL::QP__partial_base<CGAL::Quadratic_program<int>, CGAL::Gmpz, CGAL::QP_solver_impl::QP_tags<CGAL::Boolean_tag<false>, CGAL::Boolean_tag<false> > >::entering_basis(__gnu_cxx::__normal_iterator<int const*, std::vector<int, std::allocator<int> > >)':
first_qp.cpp:(.text._ZN4CGAL16QP__partial_baseINS_17Quadratic_programIiEENS_4GmpzENS_14QP_solver_impl7QP_tagsINS_11Boolean_tagILb0EEES7_EEE14entering_basisEN9__gnu_cxx17__normal_iteratorIPKiSt6vectorIiSaIiEEEE[_ZN4CGAL16QP__partial_baseINS_17Quadratic_programIiEENS_4GmpzENS_14QP_solver_impl7QP_tagsINS_11Boolean_tagILb0EEES7_EEE14entering_basisEN9__gnu_cxx17__normal_iteratorIPKiSt6vectorIiSaIiEEEE]+0xa0): undefined reference to `CGAL::precondition_fail(char const*, char const*, int, char const*)'
/tmp/ccPeDUda.o: In function `CGAL::QP_solver<CGAL::Quadratic_program<int>, CGAL::Gmpz, CGAL::QP_solver_impl::QP_tags<CGAL::Boolean_tag<false>, CGAL::Boolean_tag<false> > >::nonbasic_original_variable_bound_index(int) const':
first_qp.cpp:(.text._ZNK4CGAL9QP_solverINS_17Quadratic_programIiEENS_4GmpzENS_14QP_solver_impl7QP_tagsINS_11Boolean_tagILb0EEES7_EEE38nonbasic_original_variable_bound_indexEi[_ZNK4CGAL9QP_solverINS_17Quadratic_programIiEENS_4GmpzENS_14QP_solver_impl7QP_tagsINS_11Boolean_tagILb0EEES7_EEE38nonbasic_original_variable_bound_indexEi]+0x80): undefined reference to `CGAL::assertion_fail(char const*, char const*, int, char const*)'
first_qp.cpp:(.text._ZNK4CGAL9QP_solverINS_17Quadratic_programIiEENS_4GmpzENS_14QP_solver_impl7QP_tagsINS_11Boolean_tagILb0EEES7_EEE38nonbasic_original_variable_bound_indexEi[_ZNK4CGAL9QP_solverINS_17Quadratic_programIiEENS_4GmpzENS_14QP_solver_impl7QP_tagsINS_11Boolean_tagILb0EEES7_EEE38nonbasic_original_variable_bound_indexEi]+0xd1): undefined reference to `CGAL::assertion_fail(char const*, char const*, int, char const*)'
/tmp/ccPeDUda.o: In function `CGAL::QP_solver<CGAL::Quadratic_program<int>, CGAL::Gmpz, CGAL::QP_solver_impl::QP_tags<CGAL::Boolean_tag<false>, CGAL::Boolean_tag<false> > >::state_of_zero_nonbasic_variable(int) const':
first_qp.cpp:(.text._ZNK4CGAL9QP_solverINS_17Quadratic_programIiEENS_4GmpzENS_14QP_solver_impl7QP_tagsINS_11Boolean_tagILb0EEES7_EEE31state_of_zero_nonbasic_variableEi[_ZNK4CGAL9QP_solverINS_17Quadratic_programIiEENS_4GmpzENS_14QP_solver_impl7QP_tagsINS_11Boolean_tagILb0EEES7_EEE31state_of_zero_nonbasic_variableEi]+0xc1): undefined reference to `CGAL::assertion_fail(char const*, char const*, int, char const*)'
You can use cmake to resolve these types of conflicts. ex:
cgal_create_CMakeLists -s executable
cmake .
make
The example mentioned achieved success.
I have installed Armadillo in Ubuntu 14.10. I have an example code likes below
#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;
return 0;
}
I compiled in command line, it is always successful, I depict in captured image.
I have eclipse Luna for C++ and config in C/C++ Build Settings
As you can see, it is similar to command line but when eclipse compiles, it use -Iarmadillo instead of -larmadillo and it then occurs errors.
The errors were
make all Building file: ../src/Test.cpp Invoking: GCC C++ Compiler
g++ -std=c++0x -Iarmadillo -O0 -MMD -MP -MF"src/Test.d"
-MT"src/Test.d" -o "src/Test.o" "../src/Test.cpp" /tmp/ccy9M8WG.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*)':
Test.cpp:(.text._ZN4arma4blas4gemvIdEEvPKcPKiS5_PKT_S8_S5_S8_S5_S8_PS6_S5_[_ZN4arma4blas4gemvIdEEvPKcPKiS5_PKT_S8_S5_S8_S5_S8_PS6_S5_]+0x55):
undefined reference towrapper_dgemv_' /tmp/ccy9M8WG.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*)':
Test.cpp:(.text._ZN4arma4blas4gemmIdEEvPKcS3_PKiS5_S5_PKT_S8_S5_S8_S5_S8_PS6_S5_[_ZN4arma4blas4gemmIdEEvPKcS3_PKiS5_S5_PKT_S8_S5_S8_S5_S8_PS6_S5_]+0x5b):
undefined reference towrapper_dgemm_' /tmp/ccy9M8WG.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*)':
Test.cpp:(.text._ZN4arma4blas4syrkIdEEvPKcS3_PKiS5_PKT_S8_S5_S8_PS6_S5_[_ZN4arma4blas4syrkIdEEvPKcS3_PKiS5_PKT_S8_S5_S8_PS6_S5_]+0x4e):
undefined reference towrapper_dsyrk_' /tmp/ccy9M8WG.o: In function
double arma::blas::dot<double>(unsigned int, double const*, double
const*)':
Test.cpp:(.text._ZN4arma4blas3dotIdEET_jPKS2_S4_[_ZN4arma4blas3dotIdEET_jPKS2_S4_]+0x4a):
undefined reference towrapper_ddot_' /tmp/ccy9M8WG.o: In function
TLS wrapper function for arma::arma_rng_cxx11_instance':
Test.cpp:(.text._ZTWN4arma23arma_rng_cxx11_instanceE[_ZTWN4arma23arma_rng_cxx11_instanceE]+0x5):
undefined reference toTLS init function for
arma::arma_rng_cxx11_instance'
Test.cpp:(.text._ZTWN4arma23arma_rng_cxx11_instanceE[_ZTWN4arma23arma_rng_cxx11_instanceE]+0x15):
undefined reference to `arma::arma_rng_cxx11_instance' collect2:
error: ld returned 1 exit status src/subdir.mk:18: recipe for target
'src/Test.o' failed make: *** [src/Test.o] Error 1
My questions are
How can I force eclipse use -larmadillo?
What happened to this phenomenon?
Thank you in advance
You can also create GNU Autotools projects and add following line:
bin_PROGRAMS=armadillo_example
armadillo_example_SOURCES=armadillo_example.cpp
armadillo_example_LDADD=-larmadillo
To Makefile.am file where your source code exist.
You may not be linking with Armadillo. Use -larmadillo in your link as Hamed suggested.
I have downloaded the latest Armadillo package (3.920) and I am trying to use it on my machine (Ubuntu 12.04). I am following the steps mentioned in the readme.txt file for the installation (cmake ., make, sudo make install). I have lapack and blas on my system. When I try to run the example provided in the examples directory using:
g++ example1.cpp -O2 -larmadillo
I get the error:
/usr/lib/liblapack.so.3gf: undefined reference to ATL_zptgemm'
/usr/lib/liblapack.so.3gf: undefined reference toATL_scopy'
etc
If I try to run the example with
g++ example1.cpp -O2 -llpack -lblas -lgfortran
I get the error:
/tmp/ccOsKhfg.o: In function double arma::blas::dot<double>(unsigned int, double const*, double const*)':
example1.cpp:(.text._ZN4arma4blas3dotIdEET_jPKS2_S4_[double arma::blas::dot<double>(unsigned int, double const*, double const*)]+0x36): undefined reference towrapper_ddot_'
/tmp/ccOsKhfg.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*)':
example1.cpp:(.text._ZN4arma4blas4gemvIdEEvPKcPKiS5_PKT_S8_S5_S8_S5_S8_PS6_S5_[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*)]+0x53): undefined reference towrapper_dgemv_'
/tmp/ccOsKhfg.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*)':
example1.cpp:(.text._ZN4arma4blas4gemmIdEEvPKcS3_PKiS5_S5_PKT_S8_S5_S8_S5_S8_PS6_S5_[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*)]+0x61): undefined reference towrapper_dgemm_'
Note that if I comment lines '#define ARMA_USE_LAPACK','#define ARMA_USE_BLAS'in config.hpp I am able to run example 1 but not example 2 as it requires lapack.
Can you please guide me in solving the problem.
Thanks.
Salil
By seeing your question,
i think you should type -llapack instead of -llpack.
Without -lgfortan it can work so try that too.
g++ main.cpp -o main -o1 -larmadillo -llapack -lblas
The code is as follows:
#include <stdio.h>
#include <math.h>
#include <vector>
float comp_cur(float A_x, float A_y, float B_x, float B_y, float C_x, float C_y);
void comp_arr(std::vector<float> vals, std::vector<float> out, int scale, float dim);
main(){
std::vector <float> curves;
std::vector <float> inputs;
inputs.push_back(2.0);
inputs.push_back(3.0);
inputs.push_back(6.0);
inputs.push_back(1.0);
inputs.push_back(7.0);
comp_arr(inputs,curves,1.0,1.0);
}
float comp_cur(float A_x, float A_y, float B_x, float B_y, float C_x, float C_y){
B_x = B_x-A_x;
B_y = B_y-A_y;
C_x = C_x-A_x;
C_y = C_y-A_y;
A_x = 0;
A_y = 0;
float numerator_A = C_y*B_x - B_y*C_x;
float denominator_A = C_x*C_x*B_x - C_x*B_x*B_x;
float A = numerator_A / denominator_A;
float B = (B_y - A*B_x*B_x) / B_x;
float curviture = 2*A / powf( (1 + (2*A*B_x + B)*(2*A*B_x + B)), 1.5);
return (curviture);
}
void comp_arr(std::vector<float> vals, std::vector<float> out, int scale, float dim){
for(int i = scale; i < sizeof(vals)-scale+1; i++){
float cur = comp_cur((i-scale)*dim, vals[i-1], i*dim, vals[i], (i+scale)*dim, vals[i+1]);
out.push_back(cur);
}
}
Everything about comp_cur works fine, but the comp_arr function is throwing a hideous error. I'm pretty new to C and C++ so I can't make any sense of this error at all.
/tmp/ccTCZ2bX.o: In function `main':
comp.cpp:(.text+0x174): undefined reference to `__cxa_end_cleanup'
/tmp/ccTCZ2bX.o:(.ARM.extab+0x0): undefined reference to `__gxx_personality_v0'
/tmp/ccTCZ2bX.o: In function `std::vector<float, std::allocator<float> >::~vector()':
comp.cpp:(.text._ZNSt6vectorIfSaIfEED2Ev[_ZNSt6vectorIfSaIfEED5Ev]+0x6c): undefined reference to `__cxa_end_cleanup'
/tmp/ccTCZ2bX.o:(.ARM.extab.text._ZNSt6vectorIfSaIfEED2Ev[_ZNSt6vectorIfSaIfEED5Ev]+0x0): undefined reference to `__gxx_personality_v0'
/tmp/ccTCZ2bX.o: In function `std::vector<float, std::allocator<float> >::vector(std::vector<float, std::allocator<float> > const&)':
comp.cpp:(.text._ZNSt6vectorIfSaIfEEC2ERKS1_[_ZNSt6vectorIfSaIfEEC5ERKS1_]+0xb4): undefined reference to `__cxa_end_cleanup'
/tmp/ccTCZ2bX.o:(.ARM.extab.text._ZNSt6vectorIfSaIfEEC2ERKS1_[_ZNSt6vectorIfSaIfEEC5ERKS1_]+0x0): undefined reference to `__gxx_personality_v0'
/tmp/ccTCZ2bX.o: In function `std::_Vector_base<float, std::allocator<float> >::~_Vector_base()':
comp.cpp:(.text._ZNSt12_Vector_baseIfSaIfEED2Ev[_ZNSt12_Vector_baseIfSaIfEED5Ev]+0x70): undefined reference to `__cxa_end_cleanup'
/tmp/ccTCZ2bX.o:(.ARM.extab.text._ZNSt12_Vector_baseIfSaIfEED2Ev[_ZNSt12_Vector_baseIfSaIfEED5Ev]+0x0): undefined reference to `__gxx_personality_v0'
/tmp/ccTCZ2bX.o: In function `std::vector<float, std::allocator<float> >::_M_insert_aux(__gnu_cxx::__normal_iterator<float*, std::vector<float, std::allocator<float> > >, float const&)':
comp.cpp:(.text._ZNSt6vectorIfSaIfEE13_M_insert_auxEN9__gnu_cxx17__normal_iteratorIPfS1_EERKf[std::vector<float, std::allocator<float> >::_M_insert_aux(__gnu_cxx::__normal_iterator< float*, std::vector<float, std::allocator<float> > >, float const&)]+0x290): undefined reference to `__cxa_end_catch'
comp.cpp:(.text._ZNSt6vectorIfSaIfEE13_M_insert_auxEN9__gnu_cxx17__normal_iteratorIPfS1_EERKf[std::vector<float, std::allocator<float> >::_M_insert_aux(__gnu_cxx::__normal_iterator< float*, std::vector<float, std::allocator<float> > >, float const&)]+0x294): undefined reference to `__cxa_end_cleanup'
comp.cpp:(.text._ZNSt6vectorIfSaIfEE13_M_insert_auxEN9__gnu_cxx17__normal_iteratorIPfS1_EERKf[std::vector<float, std::allocator<float> >::_M_insert_aux(__gnu_cxx::__normal_iterator< float*, std::vector<float, std::allocator<float> > >, float const&)]+0x2a0): undefined reference to `__cxa_begin_catch'
comp.cpp:(.text._ZNSt6vectorIfSaIfEE13_M_insert_auxEN9__gnu_cxx17__normal_iteratorIPfS1_EERKf[std::vector<float, std::allocator<float> >::_M_insert_aux(__gnu_cxx::__normal_iterator< float*, std::vector<float, std::allocator<float> > >, float const&)]+0x308): undefined reference to `__cxa_rethrow'
/tmp/ccTCZ2bX.o:(.ARM.extab.text._ZNSt6vectorIfSaIfEE13_M_insert_auxEN9__gnu_cxx17__normal_iteratorIPfS1_EERKf[std::vector<float, std::allocator<float> >::_M_insert_aux(__gnu_cxx::__normal_iterator<float*, std::vector<float, std::allocator<float> > >, float const&)]+0x0): undefined reference to `__gxx_personality_v0'
/tmp/ccTCZ2bX.o: In function `std::_Vector_base<float, std::allocator<float> >::_Vector_base(unsigned int, std::allocator<float> const&)':
comp.cpp:(.text._ZNSt12_Vector_baseIfSaIfEEC2EjRKS0_[_ZNSt12_Vector_baseIfSaIfEEC5EjRKS0_]+0x90): undefined reference to `__cxa_end_cleanup'
/tmp/ccTCZ2bX.o:(.ARM.extab.text._ZNSt12_Vector_baseIfSaIfEEC2EjRKS0_[_ZNSt12_Vector_baseIfSaIfEEC5EjRKS0_]+0x0): undefined reference to `__gxx_personality_v0'
/tmp/ccTCZ2bX.o: In function `std::vector<float, std::allocator<float> >::_M_check_len(unsigned int, char const*) const':
comp.cpp:(.text._ZNKSt6vectorIfSaIfEE12_M_check_lenEjPKc[std::vector<float, std::allocator<float> >::_M_check_len(unsigned int, char const*) const]+0x54): undefined reference to `std::__throw_length_error(char const*)'
/tmp/ccTCZ2bX.o: In function `__gnu_cxx::new_allocator<float>::deallocate(float*, unsigned int)':
comp.cpp:(.text._ZN9__gnu_cxx13new_allocatorIfE10deallocateEPfj[__gnu_cxx::new_allocator<float>::deallocate(float*, unsigned int)]+0x1c): undefined reference to `operator delete(void*)'
/tmp/ccTCZ2bX.o: In function `__gnu_cxx::new_allocator<float>::allocate(unsigned int, void const*)':
comp.cpp:(.text._ZN9__gnu_cxx13new_allocatorIfE8allocateEjPKv[__gnu_cxx::new_allocator<float>::allocate(unsigned int, void const*)]+0x40): undefined reference to `std::__throw_bad_alloc()'
comp.cpp:(.text._ZN9__gnu_cxx13new_allocatorIfE8allocateEjPKv[__gnu_cxx::new_allocator<float>::allocate(unsigned int, void const*)]+0x50): undefined reference to `operator new(unsigned int)'
collect2: ld returned 1 exit status
I'll take an educated guess without knowing how you're compiling.
Make sure you compile with g++ rather than gcc - g++ automatically sets up some options for compiling c++ for you, including linking to the standard library. Alternatively, give the -lstdc++ and -x c++ options.