下Eigen3でCholmodSupportを使用する方法:私は、このような小さな例作られたUbuntuの
solver.h
#pragma once
#include <Eigen/Dense>
#include <Eigen/Sparse>
#include <Eigen/CholmodSupport>
typedef Eigen::SparseMatrix<double> SpMat;
class UseCholmodSolver
{
public:
UseCholmodSolver() {}
~UseCholmodSolver() {}
private:
Eigen::CholmodSupernodalLLT<SpMat> cholmod;
};
solver.cpp
#include "solver.h"
main.cppに
#include "solver.h"
int main()
{
return 0;
}
メイクファイル
CXXFLAGS=-g -O2 -Wall -DNDEBUG -I./ext/eigen -I/usr/include/suitesparse
CXX=g++
all: t1
clean:
rm -f *.o main
main.o: main.cpp solver.h
solver.o: solver.cpp solver.h
t1: main.o
$(CXX) main.o -o main -lcholmod
t2: main.o solver.o
$(CXX) main.o solver.o -o main -lcholmod
"make t1"を実行すると、すべて正常です。私は「T2を作る」と入力するとき ただし、再定義エラーがあります
g++ main.o solver.o -o main -lcholmod
solver.o: In function `int Eigen::internal::cm_start<long>(cholmod_common_struct&)':
/home/xiang/Code/testEigen/./ext/eigen/Eigen/src/CholmodSupport/CholmodSupport.h:177: multiple definition of `int Eigen::internal::cm_start<long>(cholmod_common_struct&)'
main.o:/home/xiang/Code/testEigen/./ext/eigen/Eigen/src/CholmodSupport/CholmodSupport.h:177: first defined here
solver.o: In function `int Eigen::internal::cm_finish<long>(cholmod_common_struct&)':
/home/xiang/Code/testEigen/./ext/eigen/Eigen/src/CholmodSupport/CholmodSupport.h:178: multiple definition of `int Eigen::internal::cm_finish<long>(cholmod_common_struct&)'
main.o:/home/xiang/Code/testEigen/./ext/eigen/Eigen/src/CholmodSupport/CholmodSupport.h:178: first defined here
solver.o: In function `int Eigen::internal::cm_free_factor<long>(cholmod_factor_struct*&, cholmod_common_struct&)':
/home/xiang/Code/testEigen/./ext/eigen/Eigen/src/CholmodSupport/CholmodSupport.h:180: multiple definition of `int Eigen::internal::cm_free_factor<long>(cholmod_factor_struct*&, cholmod_common_struct&)'
main.o:/home/xiang/Code/testEigen/./ext/eigen/Eigen/src/CholmodSupport/CholmodSupport.h:180: first defined here
solver.o: In function `int Eigen::internal::cm_free_dense<long>(cholmod_dense_struct*&, cholmod_common_struct&)':
/home/xiang/Code/testEigen/./ext/eigen/Eigen/src/CholmodSupport/CholmodSupport.h:181: multiple definition of `int Eigen::internal::cm_free_dense<long>(cholmod_dense_struct*&, cholmod_common_struct&)'
main.o:/home/xiang/Code/testEigen/./ext/eigen/Eigen/src/CholmodSupport/CholmodSupport.h:181: first defined here
solver.o: In function `int Eigen::internal::cm_free_sparse<long>(cholmod_sparse_struct*&, cholmod_common_struct&)':
/home/xiang/Code/testEigen/./ext/eigen/Eigen/src/CholmodSupport/CholmodSupport.h:182: multiple definition of `int Eigen::internal::cm_free_sparse<long>(cholmod_sparse_struct*&, cholmod_common_struct&)'
main.o:/home/xiang/Code/testEigen/./ext/eigen/Eigen/src/CholmodSupport/CholmodSupport.h:182: first defined here
solver.o: In function `cholmod_factor_struct* Eigen::internal::cm_analyze<long>(cholmod_sparse_struct&, cholmod_common_struct&)':
/home/xiang/Code/testEigen/./ext/eigen/Eigen/src/CholmodSupport/CholmodSupport.h:184: multiple definition of `cholmod_factor_struct* Eigen::internal::cm_analyze<long>(cholmod_sparse_struct&, cholmod_common_struct&)'
main.o:/home/xiang/Code/testEigen/./ext/eigen/Eigen/src/CholmodSupport/CholmodSupport.h:184: first defined here
solver.o: In function `cholmod_dense_struct* Eigen::internal::cm_solve<long>(int, cholmod_factor_struct&, cholmod_dense_struct&, cholmod_common_struct&)':
/home/xiang/Code/testEigen/./ext/eigen/Eigen/src/CholmodSupport/CholmodSupport.h:187: multiple definition of `cholmod_dense_struct* Eigen::internal::cm_solve<long>(int, cholmod_factor_struct&, cholmod_dense_struct&, cholmod_common_struct&)'
main.o:/home/xiang/Code/testEigen/./ext/eigen/Eigen/src/CholmodSupport/CholmodSupport.h:187: first defined here
solver.o: In function `cholmod_sparse_struct* Eigen::internal::cm_spsolve<long>(int, cholmod_factor_struct&, cholmod_sparse_struct&, cholmod_common_struct&)':
/home/xiang/Code/testEigen/./ext/eigen/Eigen/src/CholmodSupport/CholmodSupport.h:190: multiple definition of `cholmod_sparse_struct* Eigen::internal::cm_spsolve<long>(int, cholmod_factor_struct&, cholmod_sparse_struct&, cholmod_common_struct&)'
main.o:/home/xiang/Code/testEigen/./ext/eigen/Eigen/src/CholmodSupport/CholmodSupport.h:190: first defined here
solver.o: In function `int Eigen::internal::cm_factorize_p<long>(cholmod_sparse_struct*, double*, long*, unsigned long, cholmod_factor_struct*, cholmod_common_struct&)':
/home/xiang/Code/testEigen/./ext/eigen/Eigen/src/CholmodSupport/CholmodSupport.h:195: multiple definition of `int Eigen::internal::cm_factorize_p<long>(cholmod_sparse_struct*, double*, long*, unsigned long, cholmod_factor_struct*, cholmod_common_struct&)'
main.o:/home/xiang/Code/testEigen/./ext/eigen/Eigen/src/CholmodSupport/CholmodSupport.h:195: first defined here
collect2: error: ld returned 1 exit status
Makefile:14: recipe for target 't2' failed
make: *** [t2] Error 1
理由が「CholmodSupport.h」で「長い」タイプの特殊なテンプレート関数であるようです。この問題を解決するにはどんなアイデアですか?
[mcve](コンパイルに使用したコマンドを含む)を入力してください。 – chtz
@chtz私は最小限の例を作り、質問を編集しました。 – DeathKnight
最小の例をありがとう。これは確かにEigen内の問題です。私はすぐに修正を行うつもりです。 – chtz