C++ code compiled with g++ works, but XCode fails

  armadillo, c++, compiler-errors, xcode

I’m trying to compile a small C++ example in XCode 12.5.1 using the linear algebra library armadillo, which I’ve installed without problems:

//example.cpp

#include <armadillo>
#include <iostream>


using namespace std;
using namespace arma;

int
main(int argc, char** argv)
{
    cout << "Armadillo version: " << arma_version::as_string() << endl;
  
    cx_vec eigval;
    cx_mat eigvec;
    mat A(3,3,fill::zeros);
    eig_gen(eigval, eigvec, A);
    
    cout << A << "n";
    cout << eigval << "n";
    cout << eigvec << "n";
  
    return 0;
}

Specifically, I’m trying to figure out why the inclusion function eig_gen() gives me linking errors in XCode (removing the function call allows for proper compilation):

Undefined symbols for architecture x86_64:
  "_dgeev_", referenced from:
      void arma::lapack::geev<double>(char*, char*, int*, double*, int*, double*, double*, double*, int*, double*, int*, double*, int*, int*) in main.o
  "_dgeevx_", referenced from:
      void arma::lapack::geevx<double>(char*, char*, char*, char*, int*, double*, int*, double*, double*, double*, int*, double*, int*, int*, int*, double*, double*, double*, double*, double*, int*, 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)

Since if I compile the program using g++ on the command line,g++ example.cpp -o example -std=c++11 -O2 -larmadillo, the compilation is successful and the program outputs:

Armadillo version: 10.6.2 (Keep Calm)
        0        0        0
        0        0        0
        0        0        0

                      (0,0)
                      (0,0)
                      (0,0)

    (+1.000e+00,+0.000e+00)    (+1.000e+00,-0.000e+00)                      (0,0)
    (+0.000e+00,+1.000e+00)    (+0.000e+00,-1.000e+00)                      (0,0)
                      (0,0)                      (0,0)    (+1.000e+00,+0.000e+00)

The only change I made to XCode’s default linking setup (the project is a Command Line Tool project) is to include /usr/local/include in System Header Search Paths, so that I can use the code’s first line #include <armadillo>.

Any suggestions as to why XCode specifically might be giving me this error?

Source: Windows Questions C++

LEAVE A COMMENT