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.

Community
  • 1
  • 1
spin_orbit
  • 79
  • 1
  • 7

1 Answers1

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.

Scott Weldon
  • 9,673
  • 6
  • 48
  • 67
John Connors
  • 106
  • 1
  • 1
    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. – Hans Passant Aug 02 '16 at 23:01