用特征构建时找不到符号

C++ - Symbols no found when building with eigen

本文关键字:找不到 符号 构建 特征      更新时间:2023-10-16

我正在尝试使用特征库。但是当我尝试使用XCode在OSX Mavericks下编译时,我得到以下错误信息:

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)

我的代码或设置有什么问题?这里你可以看到我的代码:

#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;
}

缺少的函数saveAsBitmap(), buildProblem()和编译示例代码所需的其他定义在此链接中发布。

CMakeLists.txt文件位于同一个存储库的上面一个目录。我必须在该文件中添加一行cmake_minimum_required(VERSION 3.2)和删除add_dependencies(all_examples Tutorial_sparse_example)行来编译代码,现在运行良好。

您需要包含具有saveAsBitmap和buildProblem函数定义的头文件。