我正在尝试使用Eigen库。但是当我尝试使用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;
}
答案 0 :(得分:2)
编译该示例代码所需的缺失函数saveAsBitmap()
,buildProblem()
和其他定义发布在this link。
CMakeLists.txt
文件位于同一存储库中的one directory above。我必须在该文件中添加一行cmake_minimum_required(VERSION 3.2)
删除行add_dependencies(all_examples Tutorial_sparse_example)
以编译代码,现在可以正常工作。
答案 1 :(得分:1)
您需要包含具有saveAsBitmap和buildProblem函数定义的头文件。