[英]C++ - issue while porting C++ code from Visual Studio to Linux Eclipse IDE
我在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
文件。
您正在使用模板類的實例化。 首先,您可以刪除.cpp文件,該文件包含此模板類Graph
實現,並將方法的實現等放入Graph.h
文件中-此操作將無需實例化。 您可以嘗試做的下一件事是將instances.h / inc重命名為instances.cpp並進行編譯(將其放入makefile或您使用的文件中)。
我找到了一個很好的鏈接:
http://www.cplusplus.com/forum/articles/10627/
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.