Mingw32 compile errors

okay correct me if I’m wrong but shouldn’t:
gcc -DWIN32 -IC:\gcc\i386-mingw32\include\sdl
-lmingw32 -lsdlmain -lsdl -lwinmm -ldxguid -o test.exe
test.c

work just fine when compiling a simple little sdl test
program? Is that command-line setup okay? do I have
the libraries in the right order? Something must be
wrong because I get the following errors:
undefined reference to ‘SDL_SetVideoMode’
undefined reference to ‘SDL_MapRGB’
undefined reference to ‘SDL_LockSurface’
undefined reference to ‘SDL_UnlockSurface’
undefined reference to ‘SDL_UpdateRect’

I pulled the code straight out of the SDL examples in
the documentation. So it must be something I’m doing
wrong, not to mention that it’s always something I’m
doing wrong. :slight_smile:

Jared-


Do You Yahoo!?
Talk to your friends online with Yahoo! Messenger.

Do you have libsdl.a in c:\gcc\lib ?

I think that the compiler doesn’t use this folder by default. in
mingw32

You must add -LC:\gcc\lib to gcc command line.

or use the environment variable

set LIBRARY_PATH=c:/gcc/lib;c:/gcc/i386-mingw32/gcc-2.95.2/lib

advice: do not use c:/gcc/i386-mingw32/include/SDL.h
use c:/gcc/include/SDL.h

Jared wrote:> okay correct me if I’m wrong but shouldn’t:

gcc -DWIN32 -IC:\gcc\i386-mingw32\include\sdl
-lmingw32 -lsdlmain -lsdl -lwinmm -ldxguid -o test.exe
test.c

work just fine when compiling a simple little sdl test
program? Is that command-line setup okay? do I have
the libraries in the right order? Something must be
wrong because I get the following errors:
undefined reference to 'SDL_SetVideoMode’
undefined reference to 'SDL_MapRGB’
undefined reference to 'SDL_LockSurface’
undefined reference to 'SDL_UnlockSurface’
undefined reference to ‘SDL_UpdateRect’

I pulled the code straight out of the SDL examples in
the documentation. So it must be something I’m doing
wrong, not to mention that it’s always something I’m
doing wrong. :slight_smile:

Jared


Do You Yahoo!?
Talk to your friends online with Yahoo! Messenger.
http://im.yahoo.com

Okay I’ve made sure libsdl.a and all it’s friends are
in the C:\gcc\lib. I’ve added -LC:\gcc\lib to the
command line and I still get the same errors. I don’t
know what’s up with it. Any other things I should
check?

Antonio wrote:

Do you have libsdl.a in c:\gcc\lib ?
I think that the compiler doesn’t use this folder by
default. in mingw32
You must add -LC:\gcc\lib to gcc command line.
advice: do not use c:/gcc/i386-mingw32/include/SDL.h
use c:/gcc/include/SDL.h

Jared-


Do You Yahoo!?
Talk to your friends online with Yahoo! Messenger.

okay correct me if I’m wrong but shouldn’t:
gcc -DWIN32 -IC:\gcc\i386-mingw32\include\sdl
-lmingw32 -lsdlmain -lsdl -lwinmm -ldxguid -o test.exe
test.c

The link order is important. In this case, test.c has no libraries following
it, and so will not get any of the symbols in the earlier libraries.

This should work:
gcc test.c -o test.exe -DWIN32 -IC:\gcc\i386-mingw32\include\sdl -lmingw32 -lsdlmain -lsdl -lwinmm -ldxguid

-Sam Lantinga				(slouken at devolution.com)

Lead Programmer, Loki Entertainment Software–
“Any sufficiently advanced bug is indistinguishable from a feature”
– Rich Kulawiec

This is something that bit me as well. It’s important to note that
libraries that require other libraries must be in the correct order as
well. For example -lz must be after -lpng.–
Brian

The link order is important. In this case, test.c has no libraries following
it, and so will not get any of the symbols in the earlier libraries.

This should work:
gcc test.c -o test.exe -DWIN32 -IC:\gcc\i386-mingw32\include\sdl -lmingw32 -lsdlmain -lsdl -lwinmm -ldxguid

correction: not “-LC:\gcc\lib” but “-Lc:/gcc/lib” "\ " replaced
by “/” my fault :slight_smile:

Jared wrote:> Okay I’ve made sure libsdl.a and all it’s friends are

in the C:\gcc\lib. I’ve added -LC:\gcc\lib to the
command line and I still get the same errors. I don’t
know what’s up with it. Any other things I should
check?

Antonio wrote:

Do you have libsdl.a in c:\gcc\lib ?
I think that the compiler doesn’t use this folder by
default. in mingw32
You must add -LC:\gcc\lib to gcc command line.
advice: do not use c:/gcc/i386-mingw32/include/SDL.h
use c:/gcc/include/SDL.h

Jared


Do You Yahoo!?
Talk to your friends online with Yahoo! Messenger.
http://im.yahoo.com

wow it works, I feel pretty dumb, but I was thinking
in the other direction. Libraries first so that it
would know what the code was talking about. Well thank
you for pointing out my simple error, I never would’ve
tried that.>The link order is important. In this case, test.c

has no libraries following it, and so will not get
any of the symbols in the earlier libraries.
This should work:
gcc test.c -o test.exe -DWIN32
-IC:\gcc\i386mingw32\include\sdl -lmingw32 -lsdlmain
-lsdl -lwinmm -ldxguid


Do You Yahoo!?
Talk to your friends online with Yahoo! Messenger.