Sign in to follow this  

linking problem with mingw

This topic is 2038 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am trying to link SDL, GL and GLew with mingw. This is my compile command:

[code]
g++ -mwindows main.cpp -o arcanacaelestia.exe
-IC:\Users\Light\Programming\SDL-1.2.15\include
-IC:\Users\Light\Programming\glew-1.7.0\include
-LC:\Users\Light\Programming\SDL-1.2.15\lib\x86
-LC:\Users\Light\Programming\glew-1.7.0\lib
-lmingw32 -lglew32 -lSDL -lSDLmain -lopengl32
[/code]

and I am having problems with SDLmain. These are the errors I get:

[code]
C:\Users\Light\Programming\SDL-1.2.15\lib\x86/SDLmain.lib(./Release/SDL_win32_ma
in.obj): (.text[_main]+0x0): multiple definition of `main'
c:/mingw/bin/../lib/gcc/mingw32/4.6.1/../../../libmingw32.a(main.o):C:\MinGW\msy
s\1.0\src\mingwrt/../mingw/main.c:24: first defined here
Warning: .drectve `/manifestdependency:"type='win32' name='Microsoft.VC90.CRT' v
ersion='9.0.21022.8' processorArchitecture='x86' publicKeyToken='1fc8b3b9a1e18e3
b'" /DEFAULTLIB:"MSVCRT" /DEFAULTLIB:"OLDNAMES" ' unrecognized
C:\Users\Light\Programming\SDL-1.2.15\lib\x86/SDLmain.lib(./Release/SDL_win32_ma
in.obj): (.text[_main]+0x7): undefined reference to `__security_cookie'
C:\Users\Light\Programming\SDL-1.2.15\lib\x86/SDLmain.lib(./Release/SDL_win32_ma
in.obj): (.text[_main]+0x99): undefined reference to `_alloca_probe_16'
C:\Users\Light\Programming\SDL-1.2.15\lib\x86/SDLmain.lib(./Release/SDL_win32_ma
in.obj): (.text[_main]+0xc6): undefined reference to `SDL_strlcpy'
C:\Users\Light\Programming\SDL-1.2.15\lib\x86/SDLmain.lib(./Release/SDL_win32_ma
in.obj): (.text[_main]+0xe5): undefined reference to `SDL_GetError'
C:\Users\Light\Programming\SDL-1.2.15\lib\x86/SDLmain.lib(./Release/SDL_win32_ma
in.obj): (.text[_main]+0x11f): undefined reference to `SDL_SetModuleHandle'
C:\Users\Light\Programming\SDL-1.2.15\lib\x86/SDLmain.lib(./Release/SDL_win32_ma
in.obj): (.text[_main]+0x14e): undefined reference to `@__security_check_cookie@4
'
C:\Users\Light\Programming\SDL-1.2.15\lib\x86/SDLmain.lib(./Release/SDL_win32_ma
in.obj): (.text[_WinMain@16]+0x7): undefined reference to `__security_cookie'
C:\Users\Light\Programming\SDL-1.2.15\lib\x86/SDLmain.lib(./Release/SDL_win32_ma
in.obj): (.text[_WinMain@16]+0x34): undefined reference to `SDL_getenv'
C:\Users\Light\Programming\SDL-1.2.15\lib\x86/SDLmain.lib(./Release/SDL_win32_ma
in.obj): (.text[_WinMain@16]+0x80): undefined reference to `_alloca_probe_16'
C:\Users\Light\Programming\SDL-1.2.15\lib\x86/SDLmain.lib(./Release/SDL_win32_ma
in.obj): (.text[_WinMain@16]+0xa7): undefined reference to `SDL_strlcpy'
C:\Users\Light\Programming\SDL-1.2.15\lib\x86/SDLmain.lib(./Release/SDL_win32_ma
in.obj): (.text[_WinMain@16]+0xca): undefined reference to `_alloca_probe_16'
C:\Users\Light\Programming\SDL-1.2.15\lib\x86/SDLmain.lib(./Release/SDL_win32_ma
in.obj): (.text[_WinMain@16]+0x10f): undefined reference to `@__security_check_co
okie@4'
C:\Users\Light\Programming\SDL-1.2.15\lib\x86/SDLmain.lib(./Release/SDL_win32_ma
in.obj):(.text[_redirect_output]+0xa): undefined reference to `__security_cookie
'
C:\Users\Light\Programming\SDL-1.2.15\lib\x86/SDLmain.lib(./Release/SDL_win32_ma
in.obj):(.text[_redirect_output]+0x6a): undefined reference to `SDL_strlcpy'
C:\Users\Light\Programming\SDL-1.2.15\lib\x86/SDLmain.lib(./Release/SDL_win32_ma
in.obj):(.text[_redirect_output]+0x81): undefined reference to `SDL_strlcat'
C:\Users\Light\Programming\SDL-1.2.15\lib\x86/SDLmain.lib(./Release/SDL_win32_ma
in.obj):(.text[_redirect_output]+0xf1): undefined reference to `SDL_strlcpy'
C:\Users\Light\Programming\SDL-1.2.15\lib\x86/SDLmain.lib(./Release/SDL_win32_ma
in.obj):(.text[_redirect_output]+0x108): undefined reference to `SDL_strlcat'
C:\Users\Light\Programming\SDL-1.2.15\lib\x86/SDLmain.lib(./Release/SDL_win32_ma
in.obj): (.text[_redirect_output]+0x1a9): undefined reference to `@__security_che
ck_cookie@4'
[/code]

I've tried with and without the -mwindows option.

SDL and SDLmain are in the path

C:\Users\Light\Programming\SDL-1.2.15\lib\x86

Share this post


Link to post
Share on other sites
Completely wild guess here, but have you tried wrapping the #includes for SDL in an extern "C" { ... }? It may have been compiled with C linkage. Edited by Shinkage

Share this post


Link to post
Share on other sites
I had a ton of different compilers and versions of the same libraries. I came to the conclusion that I'll just get rid of them all and redownload MinGW and the appropriate libraries that I need. Turns out I was linking to Visual Studio version of the SDL library with mingw... Also, it is important to put -lSDLmain before -lSDL or else I get undefined references as well. Anyways it seems to work now with the following command:

[code]
g++ main.cpp -o arcanacaelestia.exe
-IC:\Users\Light\Programming\SDL-1.2.15\include
-IC:\Users\Light\Programming\glew-1.7.0\include\GL
-LC:\Users\Light\Programming\SDL-1.2.15\lib
-LC:\Users\Light\Programming\glew-1.7.0\lib
-lmingw32 -lglew32 -lSDLmain -lSDL -lopengl32
[/code]

Share this post


Link to post
Share on other sites
It turns out I have a runtime error which I think is related to all of this because I was able to get the same code to run in MSVC. This is what I am getting:

[code]
Program received signal SIGSEGV, Segmentation fault.
0x764443f9 in strlen () from C:\Windows\syswow64\msvcrt.dll
(gdb) backtrace
#0 0x764443f9 in strlen () from C:\Windows\syswow64\msvcrt.dll
#1 0x6810a5da in SDL_strdup ()
from C:\Users\Light\Programming\ArcanaCaelestia\SDL.dll
#2 0x68126bbd in SDL_WM_SetCaption ()
from C:\Users\Light\Programming\ArcanaCaelestia\SDL.dll
#3 0x004015f6 in SDL_main ()
#4 0x00402709 in console_main (argc=1, argv=0x9d15b0)
at ./src/main/win32/SDL_win32_main.c:315
#5 0x004027cb in WinMain@16 (hInst=0x400000, hPrev=0x0,
szCmdLine=0x74377f "", sw=10) at ./src/main/win32/SDL_win32_main.c:398
#6 0x00401e66 in main (
argc=<error reading variable: Cannot access memory at address 0x10>,
argv=<error reading variable: Cannot access memory at address 0x14>,
__p__environ=<error reading variable: Cannot access memory at address 0x18>)
at ../mingw/main.c:73
[/code]

Share this post


Link to post
Share on other sites

This topic is 2038 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this