I have a bizarre problem using Qt Creator that I can’t reproduce with Visual Studio.
For the project I’m working with I have to use a third party dll, and to that end I need to include in the code also an appropriate header file. However, even though the header file has a set of
#ifndef VICON
#define VICON
//...
#endif // VICON
guards, as soon as I include the header in more than one source code file (either directly or indirectly), I get following linking errors:
-
mainwindow.obj:-1: error: LNK2005: “class std::basic_ostream > & __cdecl ViconDataStreamSDK::CPP::operator<<(class std::basic_ostream > &,class ViconDataStreamSDK::CPP::String const &)” (??6CPP@ViconDataStreamSDK@@YAAAV?$basic_ostream@DU?$char_traits@D@std@@@std@@AAV23@ABVString@01@@Z) already defined in main.obj
-
debug\Beetle_01.exe:-1: error: LNK1169: one or more multiply defined symbols found
I can provide you with the source code, but that seems to be irrelevant, even if I’m not calling anything from this DLL, as soon as the related header file appears in more than one place I get above errors. No issues if the header file is only in one place, I can then call its content and everything works as expected.
Here’s how I include the dll in the .pro file, hope it’s the right way:
INCLUDEPATH += .
win32:LIBS += ViconDataStreamSDK_CPP.lib
(And relevant lib, dll, and h files are all in the current dir)
I’m coding on Windows 7, btw.
It seems to me that the library might define the
operator<<function in a header file, but forgot to mark it asstaticorinline. This means it will be defined in all source files including the header file, and you will get the linker error you describe.