我在 Microsoft Visual Studio 中构建了一个项目,我想使用 Eclipse IDE 将它移植到 Linux(OpenSuse 12.2) 中。
该项目正在使用 OpenCV,我已设法在 Linux 中构建 OpenCV。它不是那么大,它包含 3 个 .cpp 文件和 4 个实际定义项目中使用的类的 .h 文件,其中一个 .cpp 文件包含 main()
函数。
但是,还有一个包含以下内容的附加 instances.inc
文件:
#include "graph.h"
#ifdef _MSC_VER
#pragma warning(disable: 4661)
#endif
// Instantiations: <captype, tcaptype, flowtype>
// IMPORTANT:
// flowtype should be 'larger' than tcaptype
// tcaptype should be 'larger' than captype
template class Graph<int,int,int>;
template class Graph<short,int,int>;
template class Graph<float,float,float>;
template class Graph<double,double,double>;
其中 graph.h
包含 Graph
类的声明。
我将 instances.inc
文件的扩展名更改为 instances.h
文件。但是,当我尝试构建项目时,我收到以下错误:
../src/BranchAndMincut.cpp:246: undefined reference to `Graph<int, int, int>::maxflow(bool, Block<int>*)'
我猜它与 .inc
文件有关。你知道如何解决这个问题吗?
编辑:
我还想提一下 instanes.inc
文件包含在 graph.cpp
文件的末尾。
最佳答案
您正在使用模板类的实例化。首先,您可以删除包含此模板类 Graph
实现的 .cpp 文件,并将方法等的实现放在 Graph.h
文件中 - 此操作将使实例化变得不必要。
接下来您可以尝试做的是将 instances.h/inc 重命名为 instances.cpp 并编译它(将它放在 makefile 中或您使用什么)。
我找到了一个很好的链接:
http://www.cplusplus.com/forum/articles/10627/
关于C++ - 将 C++ 代码从 Visual Studio 移植到 Linux Eclipse IDE 时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22556271/