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.