C++ - issue while porting C++ code from Visual Studio to Linux Eclipse IDE

时间:2021-02-01 12:15:21

I have a project build in Microsoft Visual Studio and I want to port it in Linux(OpenSuse 12.2) using Eclipse IDE.

我在Microsoft Visual Studio中有一个项目构建,我想使用Eclipse IDE在Linux(OpenSuse 12.2)中移植它。

The project is using OpenCV and I have managed to build OpenCV in Linux. It is not that huge, it contains 3 .cpp files and 4 .h files which actually defines the classes used in the project and one of the .cpp files contains the main() function.

该项目正在使用OpenCV,我已经设法在Linux中构建OpenCV。它不是那么大,它包含3个.cpp文件和4个.h文件,它们实际上定义了项目中使用的类,其中一个.cpp文件包含main()函数。

However, there is one additional instances.inc file with the following content:

但是,还有一个带有以下内容的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>;

where graph.h which contains the declaration of Graph class.

其中graph.h包含Graph类的声明。

I changed the extension of the instances.inc file to instances.h file. However, when I try to build the project I receive the following error:

我将instances.inc文件的扩展名更改为instances.h文件。但是,当我尝试构建项目时,我收到以下错误:

../src/BranchAndMincut.cpp:246: undefined reference to `Graph<int, int, int>::maxflow(bool, Block<int>*)'

which I guess that it is related to the .inc file. Do you know how to solve this problem?

我猜它与.inc文件有关。你知道如何解决这个问题吗?

EDIT:

编辑:

I also want to mention that instanes.inc files was included at the end of the graph.cpp file.

我还想提一下,instanes.inc文件包含在graph.cpp文件的末尾。

1 个解决方案

#1


1  

You are using instantiating of the template classes. First thing is you may delete .cpp-file which contains realization of this template class Graph and put implementation of the methods and etc in the Graph.h file - this action will make instantiating unnecessary. Next thing you can try to do is rename instances.h/inc to instances.cpp and compile it (place it in makefile or what do you use).

您正在使用模板类的实例化。首先,您可以删除包含此模板类Graph的实现的.cpp文件,并将方法的实现等放在Graph.h文件中 - 此操作将使实例化变得不必要。您可以尝试做的下一件事是将instances.h / inc重命名为instances.cpp并对其进行编译(将其放在makefile中或者您使用的是什么)。

I've found a good links:

我找到了一个很好的链接:

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

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

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

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

class template instantiation

类模板实例化

Why can templates only be implemented in the header file?

为什么模板只能在头文件中实现?

#1


1  

You are using instantiating of the template classes. First thing is you may delete .cpp-file which contains realization of this template class Graph and put implementation of the methods and etc in the Graph.h file - this action will make instantiating unnecessary. Next thing you can try to do is rename instances.h/inc to instances.cpp and compile it (place it in makefile or what do you use).

您正在使用模板类的实例化。首先,您可以删除包含此模板类Graph的实现的.cpp文件,并将方法的实现等放在Graph.h文件中 - 此操作将使实例化变得不必要。您可以尝试做的下一件事是将instances.h / inc重命名为instances.cpp并对其进行编译(将其放在makefile中或者您使用的是什么)。

I've found a good links:

我找到了一个很好的链接:

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

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

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

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

class template instantiation

类模板实例化

Why can templates only be implemented in the header file?

为什么模板只能在头文件中实现?