私はメインにいて、Eigenオブジェクトを別のクラスにある関数に渡そうとしています。両方の関数が同じファイルにある場合、問題なくこの関数呼び出しを行うことができます。問題については、サンプルコードを参照してください。リンクしません。問題は何ですか、どうすれば修正できますか?
Eigenの作成者であるeigen.tuxfamily.orgは、eigenオブジェクトを関数に渡す方法について話します。残念ながら、私は彼らの例を単一のファイルを超えて拡張することができませんでした。
オブジェクトを渡す方法:
http://eigen.tuxfamily.org/api/TopicPassingByValue.html
式テンプレートを使用してオブジェクトを渡す方法:
http://eigen.tuxfamily.org/dox/TopicFunctionTakingEigenTypes.html
main.cpp
#include <cstdlib>
#include <iostream>
#include <Eigen>
#include "MatrixMathTester.h"
using namespace std;
using namespace Eigen;
int main(int argc, char** argv)
{
MatrixMathTester matrixMathObject;
MatrixXd outputMatrix(2, 2);
outputMatrix << 22, 11, 22, 11;
matrixMathObject.internalMatrixMath(outputMatrix);
return 0;
}
MatrixMathTester.h:
#ifndef MATRIXMATHTESTER_H
#define MATRIXMATHTESTER_H
#include <iostream>
#include <Eigen>
using namespace Eigen;
class MatrixMathTester {
public:
MatrixMathTester();
MatrixMathTester(const MatrixMathTester& orig);
virtual ~MatrixMathTester();
template <typename Derived>
void internalMatrixMath(const MatrixBase<Derived>& inputMatrix);
};
#endif /* MATRIXMATHTESTER_H */
MatrixMathTester.cpp:
#include "MatrixMathTester.h"
using namespace std;
using namespace Eigen;
MatrixMathTester::MatrixMathTester(){}
MatrixMathTester::MatrixMathTester(const MatrixMathTester& orig){}
MatrixMathTester::~MatrixMathTester(){}
template <typename Derived>
void MatrixMathTester::internalMatrixMath(const MatrixBase<Derived>& inputMatrix)
{
cout << "InputMatrix" << endl << inputMatrix << endl;
}
エラー
"/usr/bin/make" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf
"/usr/bin/make" -f nbproject/Makefile-Debug.mk dist/Debug/GNU-MacOSX/testinggrounds
mkdir -p build/Debug/GNU-MacOSX
rm -f build/Debug/GNU-MacOSX/main.o.d
g++ -I/Users/folder/Documents/CPP_Librarys/eigen/Eigen -c -g \
-I../../../CPP_Library/eigen/Eigen -MMD -MP -MF
build/Debug/GNU-MacOSX/main.o.d -o build/Debug/GNU-MacOSX/main.o main.cpp
mkdir -p build/Debug/GNU-MacOSX
rm -f build/Debug/GNU-MacOSX/MatrixMathTester.o.d
g++ -I/Users/folder/Documents/CPP_Librarys/eigen/Eigen -c -g -MMD -MP \
-MF build/Debug/GNU-MacOSX/MatrixMathTester.o.d -o \
build/Debug/GNU-MacOSX/MatrixMathTester.o MatrixMathTester.cpp
mkdir -p dist/Debug/GNU-MacOSX
g++ -I/Users/folder/Documents/CPP_Librarys/eigen/Eigen -o \
dist/Debug/GNU-MacOSX/testinggrounds build/Debug/GNU-MacOSX/main.o \
build/Debug/GNU-MacOSX/MatrixMathTester.o
Undefined symbols:
"void MatrixMathTester::internalMatrixMath<Eigen::Matrix<double, -1, -1, 0, -1, -1>
>(Eigen::MatrixBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&)",
referenced from:
_main in main.o
ld: symbol(s) not found
collect2: ld returned 1 exit status