簡體   English   中英

C ++-將C ++代碼從Visual Studio移植到Linux Eclipse IDE時出現問題

[英]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/

http://www.cplusplus.com/forum/articles/14272/

類模板實例化

為什么只能在頭文件中實現模板?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM