msys2 / MINGW-packages

Package scripts for MinGW-w64 targets to build under MSYS2.
https://packages.msys2.org
BSD 3-Clause "New" or "Revised" License
2.3k stars 1.22k forks source link

'multiple definition' linking errors while linking against w32api libs #2303

Closed PASAf closed 6 years ago

PASAf commented 7 years ago

I have thousand of errors like

R:/msys64/mingw32/i686-w64-mingw32/include/psdk_inc/intrin-impl.h:1685: multiple definition of `NtCurrentTeb'
lxdream-main.o:R:/msys64/mingw32/i686-w64-mingw32/include/psdk_inc/intrin-impl.h:1685: first defined here
lxdream-gtkui.o: In function `_readfsdword':
R:/msys64/mingw32/i686-w64-mingw32/include/psdk_inc/intrin-impl.h:1685: multiple definition of `GetCurrentFiber'
lxdream-main.o:R:/msys64/mingw32/i686-w64-mingw32/include/psdk_inc/intrin-impl.h:1685: first defined here
lxdream-gtkui.o: In function `_readfsdword':
R:/msys64/mingw32/i686-w64-mingw32/include/psdk_inc/intrin-impl.h:1685: multiple definition of `GetFiberData'
lxdream-main.o:R:/msys64/mingw32/i686-w64-mingw32/include/psdk_inc/intrin-impl.h:1685: first defined here
lxdream-gtkui.o: In function `TpInitializeCallbackEnviron':
R:/msys64/mingw32/i686-w64-mingw32/include/winnt.h:8322: multiple definition of `TpInitializeCallbackEnviron'
lxdream-main.o:R:/msys64/mingw32/i686-w64-mingw32/include/winnt.h:8322: first defined here
lxdream-gtkui.o: In function `TpSetCallbackThreadpool':
R:/msys64/mingw32/i686-w64-mingw32/include/winnt.h:8338: multiple definition of `TpSetCallbackThreadpool'
lxdream-main.o:R:/msys64/mingw32/i686-w64-mingw32/include/winnt.h:8338: first defined here
lxdream-gtkui.o: In function `TpSetCallbackCleanupGroup':
R:/msys64/mingw32/i686-w64-mingw32/include/winnt.h:8339: multiple definition of `TpSetCallbackCleanupGroup'
lxdream-main.o:R:/msys64/mingw32/i686-w64-mingw32/include/winnt.h:8339: first defined here
lxdream-gtkui.o: In function `TpSetCallbackActivationContext':
R:/msys64/mingw32/i686-w64-mingw32/include/winnt.h:8343: multiple definition of `TpSetCallbackActivationContext'
lxdream-main.o:R:/msys64/mingw32/i686-w64-mingw32/include/winnt.h:8343: first defined here
lxdream-gtkui.o: In function `TpSetCallbackNoActivationContext':
R:/msys64/mingw32/i686-w64-mingw32/include/winnt.h:8344: multiple definition of `TpSetCallbackNoActivationContext'
lxdream-main.o:R:/msys64/mingw32/i686-w64-mingw32/include/winnt.h:8344: first defined here
lxdream-gtkui.o: In function `TpSetCallbackLongFunction':
R:/msys64/mingw32/i686-w64-mingw32/include/winnt.h:8345: multiple definition of `TpSetCallbackLongFunction'
lxdream-main.o:R:/msys64/mingw32/i686-w64-mingw32/include/winnt.h:8345: first defined here
lxdream-gtkui.o: In function `TpSetCallbackRaceWithDll':
R:/msys64/mingw32/i686-w64-mingw32/include/winnt.h:8346: multiple definition of `TpSetCallbackRaceWithDll'
lxdream-main.o:R:/msys64/mingw32/i686-w64-mingw32/include/winnt.h:8346: first defined here
lxdream-gtkui.o: In function `TpSetCallbackFinalizationCallback':
R:/msys64/mingw32/i686-w64-mingw32/include/winnt.h:8347: multiple definition of `TpSetCallbackFinalizationCallback'
lxdream-main.o:R:/msys64/mingw32/i686-w64-mingw32/include/winnt.h:8347: first defined here
lxdream-gtkui.o: In function `TpSetCallbackPersistent':
R:/msys64/mingw32/i686-w64-mingw32/include/winnt.h:8351: multiple definition of `TpSetCallbackPersistent'
lxdream-main.o:R:/msys64/mingw32/i686-w64-mingw32/include/winnt.h:8351: first defined here
lxdream-gtkui.o: In function `TpDestroyCallbackEnviron':
R:/msys64/mingw32/i686-w64-mingw32/include/winnt.h:8352: multiple definition of `TpDestroyCallbackEnviron'
lxdream-main.o:R:/msys64/mingw32/i686-w64-mingw32/include/winnt.h:8352: first defined here

At the bottom I get collect2.exe: error: ld returned 1 exit status

GCC run like this: gcc -D__EXTENSIONS__ -D_BSD_SOURCE -D_GNU_SOURCE -mfpmath=sse -msse2 -g -fexceptions -fno-strict-aliasing -O2 -fomit-frame-pointer -std=c99 -o lxdream.exe lxdream-main.o lxdream-gtkui.o lxdream-gtk_win.o lxdream-gtkcb.o lxdream-gtk_cfg.o lxdream-gtk_mmio.o lxdream-gtk_debug.o lxdream-gtk_dump.o lxdream-gtk_ctrl.o lxdream-gtk_gd.o lxdream-video_gtk.o lxdream-video_wgl.o lxdream-audio_sdl.o lxdream-cd_none.o liblxdream-core.a -LR:/msys64/mingw32/lib -lgtk-win32-2.0 -lgdk-win32-2.0 -lgdi32 -limm32 -lshell32 -lole32 -Wl,-luuid -lpangowin32-1.0 -lpangocairo-1.0 -lpango-1.0 -latk-1.0 -lcairo -lgdk_pixbuf-2.0 -lgio-2.0 -lgobject-2.0 -lglib-2.0 -lintl -LR:/msys64/mingw32/lib -lpng16 -LR:/msys64/mingw32/lib -lisofs -lm -lz -LR:/msys64/mingw32/lib -lgtk-win32-2.0 -lgdk-win32-2.0 -lgdi32 -limm32 -lshell32 -lole32 -Wl,-luuid -lpangowin32-1.0 -lpangocairo-1.0 -lpango-1.0 -latk-1.0 -lcairo -lgdk_pixbuf-2.0 -lgio-2.0 -lgobject-2.0 -lglib-2.0 -lintl -lopengl32 -lglu32 -lglew32 -lws2_32 -lmman -LR:/msys64/mingw32/lib -lmingw32 -lSDLmain -lSDL

No unresolved or undefined errors, just those multiple definitions.

What could cause such behaviour? How to deal with it?

revelator commented 7 years ago

allthough not the best solution you can pass -Wl,--allow-multiple-definition to LDFLAGS but be aware that if the thing your building is used to link to other stuff that this flag will propagate down to those as well so as said not the best solution. But try it and see if it runs.

PASAf commented 7 years ago

@revelator Wow, sorry, I've not paid attention to this, since it was long time ago. Well, I was able to build app, but.. it crashes, and I didn't investigated problem furthermore.

revelator commented 7 years ago

That could indicate further problems down the chain. Cant say its the first time i came across a source that would not run when i had this form of linker error, but sometimes you get lucky.

lazka commented 6 years ago

Since there hasn't been any activity here for some time: Any news on this issue? Did you figure out the problem? Can this be closed?

PASAf commented 6 years ago

@lazka Sorry, dunno if it solved from MINGW-packages side, I've used alot workarounds and tricks to get it to work, which I unnable to remember now. But yes, it is not more issue for me, so yeap, close it.

lazka commented 6 years ago

ok, thanks!

UnknownShadow200 commented 1 week ago

I'm aware this issue is from years ago now, but I ran into this same problem when compiling a fork of lxdream.

I eventually tracked this down to lxdream defining a FORCEINLINE macro, which overrode the FORCEINLINE macro defined in the mingw-w64 ntdef.h header. Changing lxdream's FORCEINLINE macro to something else fixed the linking issues for me.