Compiling Troubles

Hey everyone! :smiley:

I’ve been working on getting SDL to work for several hours but I continually
get the exact same errors no matter what compiler I’m using (and these
errors are not because of the code (I’m using many sample codes)). I’m on
windows xp and attempting to use SDL 1.2.8 currently with MinGW. Heres the
command I’m using to compile: gcc -mwindows -lSDL -lSDLmain example1.c

I hope thats enough information…

Oh, and heres the error I receive:

Wes at Computer /mingw
$ gcc -mwindows -lSDL -lSDLmain example1.c

C:/DOCUME~1/WESLEY~1/LOCALS~1/Temp/cceIaaaa.o(.text+0x38):example1.c:
undefined reference to SDL_LockSurface' C:/DOCUME~1/WESLEY~1/LOCALS~1/Temp/cceIaaaa.o(.text+0x67):example1.c: undefined reference toSDL_MapRGB’
C:/DOCUME~1/WESLEY~1/LOCALS~1/Temp/cceIaaaa.o(.text+0x1dd):example1.c:
undefined reference to SDL_UnlockSurface' C:/DOCUME~1/WESLEY~1/LOCALS~1/Temp/cceIaaaa.o(.text+0x26c):example1.c: undefined reference toSDL_Flip’
C:/DOCUME~1/WESLEY~1/LOCALS~1/Temp/cceIaaaa.o(.text+0x287):example1.c:
undefined reference to SDL_Init' C:/DOCUME~1/WESLEY~1/LOCALS~1/Temp/cceIaaaa.o(.text+0x290):example1.c: undefined reference toSDL_GetError’
C:/DOCUME~1/WESLEY~1/LOCALS~1/Temp/cceIaaaa.o(.text+0x2bf):example1.c:
undefined reference to SDL_Quit' C:/DOCUME~1/WESLEY~1/LOCALS~1/Temp/cceIaaaa.o(.text+0x2e8):example1.c: undefined reference toSDL_SetVideoMode’
C:/DOCUME~1/WESLEY~1/LOCALS~1/Temp/cceIaaaa.o(.text+0x2f6):example1.c:
undefined reference to SDL_GetError' C:/DOCUME~1/WESLEY~1/LOCALS~1/Temp/cceIaaaa.o(.text+0x393):example1.c: undefined reference toSDL_PollEvent’
/mingw/lib/libmingw32.a(main.o)(.text+0x106):main.c: undefined reference to
`WinMain at 16’
collect2: ld returned 1 exit status

Hope someone can help me. Thanks in advance!_________________________________________________________________
Don?t just search. Find. Check out the new MSN Search!
http://search.msn.click-url.com/go/onm00200636ave/direct/01/

I FINALLY got it to work! …Sort of…

After changing the order of the parameters I got it down to only one error:

/mingw/lib/libmingw32.a(main.o)(.text+0x106):main.c: undefined reference to
`WinMain at 16’

and this I fixed by searching and I found something telling me to include
windows.h and change my main(…) function to “int WINAPI WinMain(HINSTANCE
hInst, HINSTANCE hPrev, LPSTR szCmdLine, int sw)” which I don’t at all
understand but it works.-------------------------------------------------------------

I have 2 questions now:

  1. Why does the order of the parameters for gcc matter?
    $ gcc -lSDL -lSDLmain -mwindows example1.c <----gives me tons of
    errors
    $ gcc sdltest.c -lSDL -lSDLmain -mwindows <----gives me no
    errors

  2. Is it really nessisary for the fatty “int WINAPI WinMain(HINSTANCE hInst,
    HINSTANCE hPrev, LPSTR szCmdLine, int sw)” main function or is there an
    easier way (that works)?


Express yourself instantly with MSN Messenger! Download today - it’s FREE!
http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/

Link order is significant for gcc. The linker only pulls functions out
of a library which are known to be needed (when statically linking).

So specifying ‘-lSDL sdltest.o’, the linker retrieves nothing from
libSDL.a because no libSDL.a functions are currently referenced.
Whereas ‘sdltest.o -lSDL’ allows the linker to figure out which
functions sdltest.c calls, and it retrieves those functions from
libSDL.a

You can get around this by specifying these arguments…

gcc -Wl,–start-group -lSDL sdltest.o -Wl,–end-group

This makes the linker perform multiple passes to resolve missing
symbols, at the expense of link time.

Neil.On Thu, 2005-06-30 at 22:52 -0700, Wesley Erickson wrote:

I FINALLY got it to work! …Sort of…

After changing the order of the parameters I got it down to only one error:

/mingw/lib/libmingw32.a(main.o)(.text+0x106):main.c: undefined reference to
`WinMain at 16’

and this I fixed by searching and I found something telling me to include
windows.h and change my main(…) function to “int WINAPI WinMain(HINSTANCE
hInst, HINSTANCE hPrev, LPSTR szCmdLine, int sw)” which I don’t at all
understand but it works.


I have 2 questions now:

  1. Why does the order of the parameters for gcc matter?
    $ gcc -lSDL -lSDLmain -mwindows example1.c <----gives me tons of
    errors
    $ gcc sdltest.c -lSDL -lSDLmain -mwindows <----gives me no
    errors

  2. Is it really nessisary for the fatty “int WINAPI WinMain(HINSTANCE hInst,
    HINSTANCE hPrev, LPSTR szCmdLine, int sw)” main function or is there an
    easier way (that works)?


Express yourself instantly with MSN Messenger! Download today - it’s FREE!
http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

  1. Is it really nessisary for the fatty “int WINAPI WinMain(HINSTANCE hInst,
    HINSTANCE hPrev, LPSTR szCmdLine, int sw)” main function or is there an
    easier way (that works)?

Windows distinguishes between console applications (which use the
classic main(argc,argv) style main function), and graphical
applications, which use WinMain. I don’t find it too much of an
inconvenience, and the hInst parameter gets used later on during GUI
programming.

Neil.