I'm trying to built a dll file with Microsoft Visual Studio 2015 using C++. I do not use /clr nor do I use precompiled headers. I have to include two own header and c++ files (e.g. model.h and cpp and landscape.h and cpp). Both files include the same own header files (e.g. functions1.h, functions2.h). model.h and landscape.h are included in the dll.h, the corresponding cpp files are included as resource files in the project. When I compile this, I get Linker Errors because the methods of the included header files from function1.h and function2.h are included more than once. However, if I include these header files only in the dll.h file I get compiler errors because the methods defined in these header files are not known in the model.h and landscape.h. How I understand this error is that each resource file is compiled to an obj file and the linker finds the same methods in both obj files, which gives an error. However I cannot figure out how to solve this problem. I would be happy for every help. Cheers Joachim
Hmm...maybe I did not make my Problem clear. I have one header and cpp file for the dll project
//dllproject.h
#ifdef DLLFUNCTIONS
#define DLL_EXPORTS __declspec(dllexport)
#else
#define DLL_EXPORTS __declspec(dllimport)
#endif
#include <model.h>
#include <landscape.h>
using namespace std;
extern "C"
{
namespace dll_Project
{
//export functions
}
}
and here comes the corresponding .cpp file
//dllproject.cpp
#include "dllproject.h"
using namespace std;
extern "C"
{
namespace dllproject
{
//export functions
}
}
the included model.h and landscape.h are own projects in which different classes, structs and functions are difined and which include further header files with various functions. In model.h, landscape.h is included, but model.h is not in landscape.h
//model.h
#pragma once
#include <myfunctions1.h>
#include <myfunctions2.h>
#include <landscape.h>
//declarations of classes and methods
and the corresponding cpp file
//model.cpp
#include <model.h>
//definitions of the declared methods
similar is the landscape.h file
//landscape.h
#pragma once
#include <myfunctions1.h>
#include <myfunctions2.h>
//declaration of multiple classes and methods
and the corresponding cpp file:
//landscape.cpp
#include <landscape.h>
//definitions of the declared methods
myfunctions1.h and myfunctions2.h are only header files in which various different functions are declared and defined.
landscape.h and model.h are found by MVS2015 in the folder external dependencies and can be included. If I compile, the method definitions in the cpp files are not found. If I add them as resource files, the methods are found, but a linker error occurs saying that the functions from myfunctions1.h and myfunctions2.h are defined in model.obj and landscape.obj.
I would be really happy if someone could help me with that. Cheers Joachim