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

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)

// Instantiations: <captype, tcaptype, flowtype>
//    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?


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


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:



class template instantiation

Why can templates only be implemented in the header file?

Need Your Help

How to secure RESTful API that performs CRUD from a native application

.net rest restful-authentication restful-architecture restful-url

In my .NET server I use Rest API to execute CRUD operations that come from my clients (WPF, MVC, IOS and Android).