Linking program on Windows

I’ve been making a small game using SDL on Linux. I can compile, link, and
run the program on Linux, but I also want to do that with cygwin on
Windows. When I try, the linker reports undefined references to all SDL,
SDL_image, and SDL_ttf functions that I use. I have installed all three
libraries and can compile, link, and run the SDL test programs.

The SDL libraries all seem to be available:

$ ls /usr/local/lib
libSDL.a libSDL_image.a libSDL_ttf.a libSDLmain.a pkgconfig
libSDL.dll.a libSDL_image.dll.a libSDL_ttf.dll.a libfreetype.a
libSDL.la libSDL_image.la libSDL_ttf.la libfreetype.la

The output from make on my program, minus some repeated undefined
reference errors (sorry if the line breaks are a bit wrong):

gcc -Wall -ggdb -O2 -I/usr/local/include/SDL -Dmain=SDL_main -I/usr/include/mingw -DWIN32 -Uunix -mno-cygwin -I/usr/local/include/SDL/ -c -o game.o game.c
gcc -Wall -ggdb -O2 -I/usr/local/include/SDL -Dmain=SDL_main -I/usr/include/mingw -DWIN32 -Uunix -mno-cygwin -I/usr/local/include/SDL/ -c -o main.o main.c
main.c: In function SDL_main': main.c:38: warning: assignment discards qualifiers from pointer target type gcc -Wall -ggdb -O2 -I/usr/local/include/SDL -Dmain=SDL_main -I/usr/include/mingw -DWIN32 -Uunix -mno-cygwin -I/usr/local/include/SDL/ -c -o player.o player.c gcc -Wall -fno-rtti -Uuinx -L/usr/local/lib -lmingw32 -lSDLmain -lSDL -mwindows -mno-cygwin -lSDL_ttf -lSDL_image -ggdb main.o game.o player.o -o main main.o(.text+0x6c): In functionSDL_main’:
/home/jjackowski/src/tank/main.c:38: undefined reference to _SDL_GetVideoInfo' main.o(.text+0xbe):/home/jjackowski/src/tank/main.c:60: undefined reference to_SDL_SetVideoMode’
main.o(.text+0xf2):/home/jjackowski/src/tank/main.c:78: undefined reference to _TTF_Init' main.o(.text+0x10c):/home/jjackowski/src/tank/main.c:85: undefined reference to_SDL_WM_SetCaption’
main.o(.text+0x12a):/home/jjackowski/src/tank/main.c:95: undefined reference to_SDL_GetTicks' main.o(.text+0x144):/home/jjackowski/src/tank/main.c:188: undefined reference to_SDL_PollEvent’
main.o(.text+0x1d6):/home/jjackowski/src/tank/main.c:242: undefined reference to _SDL_PumpEvents' main.o(.text+0x210):/home/jjackowski/src/tank/main.c:247: undefined reference to_TTF_Quit’
main.o(.text+0x22e):/home/jjackowski/src/tank/main.c:231: undefined reference to _SDL_Delay' main.o(.text+0x238):/home/jjackowski/src/tank/main.c:212: undefined reference to_SDL_Flip’
main.o(.text+0x303):/home/jjackowski/src/tank/main.c:142: undefined reference to _SDL_WM_ToggleFullScreen' main.o(.text+0x3b4):/home/jjackowski/src/tank/main.c:175: undefined reference to_SDL_SetVideoMode’
main.o(.text+0x41e):/home/jjackowski/src/tank/main.c:89: undefined reference to_TTF_Quit' game.o(.text+0xf): In functionGraphicReset’:
/home/jjackowski/src/tank/game.c:85: undefined reference to _IMG_Load' game.o(.text+0x3c):/home/jjackowski/src/tank/game.c:90: undefined reference to_SDL_ConvertSurface’
game.o(.text+0x83):/home/jjackowski/src/tank/game.c:100: undefined reference to_SDL_MapRGBA' game.o(.text+0x148):/home/jjackowski/src/tank/game.c:108: undefined reference to_TTF_OpenFont’
game.o(.text+0x176):/home/jjackowski/src/tank/game.c:111: undefined reference to _TTF_RenderText_Blended' game.o(.text+0x18c):/home/jjackowski/src/tank/game.c:106: undefined reference to_TTF_CloseFont’
game.o(.text+0x196):/home/jjackowski/src/tank/game.c:97: undefined reference to_SDL_FreeSurface' game.o(.text+0x835): In functionIsCollidingTank’:
/home/jjackowski/src/tank/game.c:323: undefined reference to _SDL_FillRect' game.o(.text+0x946): In functionDrawTank’:
/home/jjackowski/src/tank/game.c:371: undefined reference to _SDL_FillRect' game.o(.text+0x9dc): In functionRender’:
/home/jjackowski/src/tank/game.c:399: undefined reference to _SDL_UpperBlit' game.o(.text+0xa47):/home/jjackowski/src/tank/game.c:445: undefined reference to_SDL_UpdateRect’
game.o(.text+0xa78):/home/jjackowski/src/tank/game.c:439: undefined reference to _SDL_UpperBlit' game.o(.text+0xc8f): In functionGameUninit’:
/home/jjackowski/src/tank/game.c:450: undefined reference to _TTF_CloseFont' game.o(.text+0xc9c):/home/jjackowski/src/tank/game.c:451: undefined reference to_SDL_FreeSurface’
player.o(.text+0x24): In function ReadPlayer': /home/jjackowski/src/tank/player.c:19: undefined reference to_ntohl at 4’
player.o(.text+0x57):/home/jjackowski/src/tank/player.c:23: undefined reference to _ntohs at 4' player.o(.text+0xc4): In functionWritePlayer’:
/home/jjackowski/src/tank/player.c:41: undefined reference to _htonl at 4' player.o(.text+0xf7):/home/jjackowski/src/tank/player.c:45: undefined reference to_htons at 4’
collect2: ld returned 1 exit status
make: *** [main] Error 1

How can I fix this problem? Thanks in advance for any help!–
Jeff Jackowski
http://ro.com/~jeffj/

gcc -Wall -fno-rtti -Uuinx -L/usr/local/lib -lmingw32 -lSDLmain -lSDL
-mwindows -mno-cygwin -lSDL_ttf -lSDL_image -ggdb main.o game.o player.o-o main

It’s just an idea but have u already tried to put -lSDLmain as last librry
to include, cauz if i remember right, gcc binds the libraries in the order u
write them and i dont know maybe it’ll help, maybe it’s shit what i’m saying
here :stuck_out_tongue:
try it out ;)–

P.O.M.P.E.I. du 47-20

gcc -Wall -fno-rtti -Uuinx -L/usr/local/lib -lmingw32 -lSDLmain -lSDL
-mwindows -mno-cygwin -lSDL_ttf -lSDL_image -ggdb main.o game.o player.o-o main

It’s just an idea but have u already tried to put -lSDLmain as last librry
to include, cauz if i remember right, gcc binds the libraries in the order u
write them and i dont know maybe it’ll help, maybe it’s shit what i’m saying
here :stuck_out_tongue:
try it out :wink:

I gave it a try. It caused undefined references in SDLmain. So I started
playing with the ordering and got this command to compile and link:

gcc -Wall -fno-rtti -L/usr/local/lib -mwindows -mno-cygwin -Uuinx -ggdb
main.o game.o player.o -lws2_32 -lSDL_ttf -lSDL_image -lmingw32 -lSDLmain
-lSDL -o main

I found that if I didn’t specify the libraries after my object files, then
SDL references in my objects could not be resolved. gcc on Linux doesn’t
seem to care about the ordering. Anyone know why it matters on Windows?

The resulting program when run immediately delivers this error: The
application failed to initialize properly (0xc0000022).

Insight shows the program dies with a segault before it gets to the SDL
supplied main(). I’m trying to figure it out.On Sun, 22 May 2005, Pompei2 wrote:


Jeff Jackowski
http://ro.com/~jeffj/

gcc -Wall -fno-rtti -L/usr/local/lib -mwindows -mno-cygwin -Uuinx -ggdb
main.o game.o player.o -lws2_32 -lSDL_ttf -lSDL_image -lmingw32 -lSDLmain
-lSDL -o main

I found that if I didn’t specify the libraries after my object files, then
SDL references in my objects could not be resolved. gcc on Linux doesn’t
seem to care about the ordering. Anyone know why it matters on Windows?

Ok i really don’t know, i have no real experience with gcc on windows. Sorry

The resulting program when run immediately delivers this error: The

application failed to initialize properly (0xc0000022).

Oh that’s not nice ^^
I really can’t help you more, i only use gcc on linux and never had this
error :S the only thing i can tell you is that i use Open Watcom on windows
and it works for me, and it seems watcom uses the gcc compiler …
I already had problems that my app didn’t find the entry point while using
the SDLmain library and i solved it but i dont remember how i done it, i
think i made a simple main (not winmain) and ignored SDLmain because i
didn’t see his utility :stuck_out_tongue:
Not shure … sorry–

P.O.M.P.E.I. du 47-20

Extracted from the makefile of a project using SDL building with minGW:---------------------
CC = /c/MinGW/bin/gcc

LIBS = c:/MinGW/lib/libmingw32.a c:/MinGW/lib/libSDLmain.a c:/MinGW/lib/libSDL.dll.a

target : $(OBJECTS)
$(CC) -o targetname $(OBJECTS) $(LIBS)

Jeff Jackowski <jeffj1 hiwaay.net> writes:

I gave it a try. It caused undefined references in SDLmain. So I started
playing with the ordering and got this command to compile and link:

gcc -Wall -fno-rtti -L/usr/local/lib -mwindows -mno-cygwin -Uuinx -ggdb
main.o game.o player.o -lws2_32 -lSDL_ttf -lSDL_image -lmingw32 -lSDLmain
-lSDL -o main

I found that if I didn’t specify the libraries after my object files, then
SDL references in my objects could not be resolved. gcc on Linux doesn’t
seem to care about the ordering. Anyone know why it matters on Windows?

I wrestled with this one, too. Actually, info ld says:

-lARCHIVE'–library=ARCHIVE’

 ...

 The linker will search an archive only once, at the location where
 it is specified on the command line.  If the archive defines a
 symbol which was undefined in some object which appeared before
 the archive on the command line, the linker will include the
 appropriate file(s) from the archive.  However, an undefined
 symbol in an object appearing later on the command line will not
 cause the linker to search the archive again.

However Linux native ld seems to have no problem with having archives before the
object files on the command line. It’s only with the mingw32 cross-compiler I
had to stick to this rule.> On Sun, 22 May 2005, Pompei2 wrote: