physicsGuy
physicsGuy

Reputation: 3675

C++ - Symbols no found when building with eigen

I am trying to use the Eigen library. But when I try to compile under OSX Mavericks using XCode I get the following error message:

Undefined symbols for architecture x86_64:
  "buildProblem(std::__1::vector<Eigen::Triplet<double, int>,  std::__1::allocator<Eigen::Triplet<double, int> > >&, Eigen::Matrix<double, -1, 1, 0, -1, 1>&, int)", referenced from:
  _main in main.o
  "saveAsBitmap(Eigen::Matrix<double, -1, 1, 0, -1, 1> const&, int, char const*)", referenced from:
  _main 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)

What can be wrong with my code or settings? Here you can see my code:

#include <iostream>
#include </usr/local/include/Eigen/Eigen/Sparse>
#include <vector>


typedef Eigen::SparseMatrix<double> SpMat; // declares a column-major sparse matrix type of double
typedef Eigen::Triplet<double> T;
void buildProblem(std::vector<T>& coefficients, Eigen::VectorXd& b, int n);
void saveAsBitmap(const Eigen::VectorXd& x, int n, const char* filename);



int main(int argc, char** argv)
{
    int n = 300;  // size of the image
   int m = n*n;  // number of unknows (=number of pixels)
    // Assembly:
    std::vector<T> coefficients;            // list of non-zeros coefficients
    Eigen::VectorXd b(m);                   // the right hand side-vector resulting from the constraints
    buildProblem(coefficients, b, n);
    SpMat A(m,m);
    A.setFromTriplets(coefficients.begin(), coefficients.end());
    // Solving:
    Eigen::SimplicialCholesky<SpMat> chol(A);  // performs a Cholesky factorization of A
    Eigen::VectorXd x = chol.solve(b);         // use the factorization to solve for the given right hand side
    // Export the result to a file:
    saveAsBitmap(x, n, argv[1]);
    return 0;
}

Upvotes: 1

Views: 1502

Answers (2)

RHertel
RHertel

Reputation: 23798

The missing functions saveAsBitmap(), buildProblem(), and other definitions required to compile that example code are posted in this link.

The CMakeLists.txt file is located one directory above in the same repository. I had to add a line cmake_minimum_required(VERSION 3.2) in that file and remove the line add_dependencies(all_examples Tutorial_sparse_example) to compile the code, which now works just fine.

Upvotes: 2

Thomas of the Scotts
Thomas of the Scotts

Reputation: 60

You need to include your header files that have definitions for the saveAsBitmap and buildProblem functions.

Upvotes: 1

Related Questions