GNOME Bugzilla – Bug 607433
Compilation Error : Multiple definition
Last modified: 2021-07-05 13:23:47 UTC
Created attachment 151750 [details] The very simple that don't compile on windows When compiling on windows and using libxml2 in two cpp file, i have the error multiple definition file. To reproduce the problem i have a simple example : main.cpp -------- #include "prog1.h" #include "prog2.h" int main() { testFunc1(); testFunc2(); return 1; } prog1.h ------- void testFunc1(); prog2.h ------- void testFunc2(); prog1.cpp --------- #include <libxml/parser.h> #include <libxml/xpath.h> #include <libxml/xpathInternals.h> #include <libxml/tree.h> void testFunc1() { // do nothing } prog2.cpp --------- #include <libxml/xpathInternals.h> void testFunc2() { // do nothing } compilation ----------- mingw32-make -f Makefile.Debug mingw32-make[1]: Entering directory `C:/DevCpp/mytest' g++ -c -g -frtti -fexceptions -mthreads -Wall -DUNICODE -DQT_LARGEFILE_SUPPORT - DQT_DLL -DQT_THREAD_SUPPORT -DQT_NEEDS_QMAIN -I"..\..\Qt\2009.05\qt\include" -I" ." -I"..\..\Qt\2009.05\qt\include\ActiveQt" -I"debug" -I"..\..\Qt\2009.05\qt\mks pecs\default" -o debug\prog2.o prog2.cpp g++ -enable-stdcall-fixup -Wl,-enable-auto-import -Wl,-enable-runtime-pseudo-rel oc -mthreads -Wl -Wl,-subsystem,windows -o debug\test.exe debug/main.o debug/pro g1.o debug/prog2.o -L"c:\Qt\2009.05\qt\lib" -lmingw32 -lqtmaind debug/prog2.o: In function `Z9testFunc2v': C:\DevCpp\mytest/prog2.cpp:3: multiple definition of `forbiddenExp' debug/prog1.o:C:\DevCpp\mytest/prog1.cpp:6: first defined here debug/prog2.o: In function `Z9testFunc2v': C:\DevCpp\mytest/prog2.cpp:5: multiple definition of `emptyExp' debug/prog1.o:C:\DevCpp\mytest/prog1.cpp:8: first defined here debug/prog2.o:prog2.cpp:(.bss+0x8): multiple definition of `xmlMalloc' debug/prog1.o:prog1.cpp:(.bss+0x8): first defined here debug/prog2.o:prog2.cpp:(.bss+0xc): multiple definition of `xmlMallocAtomic' debug/prog1.o:prog1.cpp:(.bss+0xc): first defined here debug/prog2.o:prog2.cpp:(.bss+0x10): multiple definition of `xmlRealloc' debug/prog1.o:prog1.cpp:(.bss+0x10): first defined here debug/prog2.o:prog2.cpp:(.bss+0x14): multiple definition of `xmlFree' debug/prog1.o:prog1.cpp:(.bss+0x14): first defined here debug/prog2.o:prog2.cpp:(.bss+0x18): multiple definition of `xmlMemStrdup' debug/prog1.o:prog1.cpp:(.bss+0x18): first defined here debug/prog2.o:prog2.cpp:(.bss+0x20): multiple definition of `xmlXPathNAN' debug/prog1.o:prog1.cpp:(.bss+0x20): first defined here debug/prog2.o:prog2.cpp:(.bss+0x28): multiple definition of `xmlXPathPINF' debug/prog1.o:prog1.cpp:(.bss+0x28): first defined here debug/prog2.o:prog2.cpp:(.bss+0x30): multiple definition of `xmlXPathNINF' debug/prog1.o:prog1.cpp:(.bss+0x30): first defined here collect2: ld returned 1 exit status mingw32-make[1]: *** [debug\test.exe] Error 1 mingw32-make[1]: Leaving directory `C:/DevCpp/mytest' mingw32-make: *** [debug] Error 2 if i include in one of cpp file the compilation work. In the real, the two file contains parsing of different file. I attach the example. The same example compile on linux (Add library -lxml2 don't change the compilation result on windows, include is in the mingw directory)
I i change in xmlexports.h the definition by the text below the compilation work... and the program too. The problem come from the __declspec(dllexport) in a code that import the dll. /* Windows platform with GNU compiler (Mingw) */ #if defined(_WIN32) && defined(__MINGW32__) #undef XMLPUBFUN #undef XMLPUBVAR #undef XMLCALL #undef XMLCDECL /* * if defined(IN_LIBXML) this raises problems on mingw with msys * _imp__xmlFree listed as missing. Try to workaround the problem * by also making that declaration when compiling client code. */ #if defined(IN_LIBXML) #define XMLPUBFUN __declspec(dllexport) #define XMLPUBVAR __declspec(dllexport) #else #define XMLPUBFUN #if !defined(LIBXML_STATIC) #define XMLPUBVAR __declspec(dllimport) extern #else #define XMLPUBVAR extern #endif #endif #define XMLCALL __cdecl #define XMLCDECL __cdecl #if !defined _REENTRANT #define _REENTRANT #endif #endif
GNOME is going to shut down bugzilla.gnome.org in favor of gitlab.gnome.org. As part of that, we are mass-closing older open tickets in bugzilla.gnome.org which have not seen updates for a longer time (resources are unfortunately quite limited so not every ticket can get handled). If you can still reproduce the situation described in this ticket in a recent and supported software version, then please follow https://wiki.gnome.org/GettingInTouch/BugReportingGuidelines and create a new ticket at https://gitlab.gnome.org/GNOME/libxml2/-/issues/ Thank you for your understanding and your help.