multiple definition of `DllMainCRTStartup@12' while building glew on windows with mingw32
Asked Answered
B

1

7

I followed this topic: Building glew on windows with mingw but something went wrong here:

gcc -shared -Wl,-soname,libglew32.dll -Wl,--out-implib,lib/libglew32.dll.a -o lib/glew32.dll src/glew.o -L/mingw/lib -lglu32 -lopengl32 -lgdi32 -luser32 -lkernel32

I get this error:

C:\MinGW\dev_lib\glew-2.0.0>gcc -shared -Wl,-soname,libglew32.dll -Wl,--out-implib,lib/libglew32.dll.a -o lib/glew32.dll src/glew.o -L/mingw/lib -lglu32 -lopengl32 -lgdi32 -luser32 -lkernel32 src/glew.o:glew.c:(.text+0x28f80): multiple definition of `DllMainCRTStartup@12' c:/mingw/bin/../lib/gcc/mingw32/4.9.3/../../../dllcrt2.o:(.text+0x60): first defined here collect2.exe: error: ld returned 1 exit status

Thanks for help.

Ballarat answered 30/7, 2016 at 11:8 Comment(0)
T
9

You need to link with the -nostdlib option like so:

gcc -nostdlib -shared -Wl,-soname,libglew32.dll -Wl,--out-implib,lib/libglew32.dll.a    -o lib/glew32.dll src/glew.o -L/mingw/lib -lglu32 -lopengl32 -lgdi32 -luser32 -lkernel32

Glew defines DllMainCRTStartup which is also defined in the CRT. Hence your problem.

Tula answered 2/8, 2016 at 20:26 Comment(2)
If this is true, little doubt it is given the linker error, this is beyond incredibly nasty. -nostdlib is certainly not a valid workaround, very important to get the CRT initialized properly in a DLL. Proper advice should surely be to only ever use Glew in an EXE project. That's what it is was made for, a simple way to get started on OpenGL.Somniloquy
I've had this problem while following github.com/KhronosGroup/OpenCL-Guide/blob/main/chapters/… - -nostdlib stopped that link error, but then it couldn't find memset. I think it needs the DllMainCRTStartup disabling.Atom

© 2022 - 2024 — McMap. All rights reserved.