This is a Qt project which, once built, results in a dll AnTS_Core.dll so I have:
AnTs_Core.cpp
#include <windows.h>
#include "Globals.h" // my global values
extern "C"
{
__declspec(dllexport) void load();
}
void load()
{
mainDispatcher = new Dispatcher();
}
The Global header file which contains all main objects as global(because I want to call an object method from an other object):
Globals.h:
#ifndef GLOBALS_H
#define GLOBALS_H
#include "AnTS_Types.h"
#include "Dispatcher.h"
#ifdef __cplusplus
extern "C"
{
#endif
Dispatcher *mainDispatcher;
#ifdef __cplusplus
}
#endif
#endif // GLOBALS_H
The Dispatcher : header file
#ifndef DISPATCHER_H
#define DISPATCHER_H
#include "AnTS_Types.h"
#include "Device.h"
#include <list>
#include <windows.h>
class Dispatcher
{
public:
Dispatcher();
~Dispatcher();
private:
std::list<Device*> _devices;
};
#endif
Dispatcher.cpp :
#include "Dispatcher.h"
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <string.h>
#include <dirent.h>
#include <regex>
#include "Device/DEV_Struct.h"
Dispatcher::Dispatcher()
{
}
and the device (Dispatcher contains a list of devices)
Device.h
#ifndef DEVICE_H
#define DEVICE_H
#include <windows.h>
#include "Device/DEV_Struct.h"
#include "AnTS_Types.h"
#define ANTS_DEVICE_NAME_LENGHT 64
class Device
{
public:
Device(char*);
~Device();
};
#endif // DEVICE_H
Device.cpp
#include "../Includes/Device.h"
#include <string.h>
#include <iostream>
#include <cstdio>
#include "Globals.h"
Device::Device(char* dllPath)
{
}
The errors are:
LNK2005 _mainDispatcher already defined in AnTS_Core.cpp.obj
LNK1169 one or more multiply defined symbols found
The errors disappear when I comment the line #include "Globals.h"
in Device.cpp. But I want to access to global variables (to an other Dispatcher for example or to another object) from the device.cpp file.