0

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

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.

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

#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.

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:

../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?

EDIT:

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

Simon
  • 4,999
  • 21
  • 69
  • 97

1 Answers1

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).

I've found a good links:

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

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

class template instantiation

Why can templates only be implemented in the header file?

Community
  • 1
  • 1
VP.
  • 15,509
  • 17
  • 91
  • 161
  • After this step the content of the `includes.inc` will be unnecessary? Can I remove the instantiates of the `Graph` class? – Simon Mar 21 '14 at 11:11
  • After placing all the implementation part in the header file - yes, you will not need instantiating after this. – VP. Mar 21 '14 at 11:14