Compiling with MinGW under Windows

Hi,

i want to compile a small test-application with MinGW under Windows (it’s
compiling finde under Linux).
It uses SDL and SDL_mixer.
I’ve installed MinGW, SDL-Develop for MinGW and SDL_Mixer-Develop.

Compiling goes fine:
g++ -c -I"C:/SDL/include" -I"C:/SDL_mixer/include" sdltest.cpp

But linking:
g++ -o sdltest.exe -L"C:/SDL/lib" -L"C:/SDL_mixer/lib" -lmingw32 -lSDLmain -lSDL
-lSDL_mixer -mwindows sdltest.o
sdltest.o(.text+0x142b):sdltest.cpp: undefined reference to SDL_SetVideoMode' sdltest.o(.text+0x144b):sdltest.cpp: undefined reference toSDL_MapRGB’
sdltest.o(.text+0x1459):sdltest.cpp: undefined reference to SDL_FillRect' sdltest.o(.text+0x1535):sdltest.cpp: undefined reference toSDL_RWFromFile’
[…]

I don’t get it: The paths’ are correct, all Headers and libs are in the
directories…

Thanks for any help in advance.

Tino

I don’t get it: The paths’ are correct, all Headers and libs
are in the directories…

I’m not 100% sure why, but in some cases changing the order (yes,
the order) of the libraries passed to the linker help fix weird
things like these. Try, for example,

g++ -mwindows sdltest.o -lSDL -lSDL_mixer -lSDLmain

Ing. Gabriel Gambetta
ARTech - GeneXus Development Team
ggambett at artech.com.uy

g++ -o sdltest.exe -L"C:/SDL/lib" -L"C:/SDL_mixer/lib" -lmingw32
-lSDLmain -lSDL -lSDL_mixer -mwindows sdltest.o

As Gabriel wrote, you must put sdltest.o before the libraries list,
otherwise the linker doesn’t know that SDL functions are needed when it
"reads" libSDL.a and thus doesn’t include them. GCC’s linker "reads"
link libs and objects from left to right… It won’t include function
if it doesn’t know that they are needed.

A “-Dmain=SDLmain” might be helpful too; I know it’s here in my DEVC++
projects.On 23/03/2004, Tino Miegel, you wrote:


Please remove “.ARGL.invalid” from my email when replying.
Incoming HTML mails are automatically deleted.

Sorry, I made a small mistake,On 23/03/2004, Tino Miegel, you wrote:

g++ -c -I"C:/SDL/include" -I"C:/SDL_mixer/include" sdltest.cpp

You should(?) add “-Dmain=SDL_main” (and not “SDLmain” like I wrote in
my previous mail).

Again, I’m not sure if it’s necessary with your dev installation… but
it is here under DEVC++.


Please remove “.ARGL.invalid” from my email when replying.
Incoming HTML mails are automatically deleted.

Gabriel Gambetta wrote:

I don’t get it: The paths’ are correct, all Headers and libs
are in the directories…

I’m not 100% sure why, but in some cases changing the order (yes,
the order) of the libraries passed to the linker help fix weird
things like these. Try, for example,

g++ -mwindows sdltest.o -lSDL -lSDL_mixer -lSDLmain

Ing. Gabriel Gambetta
ARTech - GeneXus Development Team
ggambett at artech.com.uy


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

My favorite way is:

g++ -mwindows -lSDLmain -lSDL -lSDL_mixer sdltest.o

In some cases, putting SDLmain ahead of SDL makes it works. Also make
sure that you are not using <SDL/SDL.h>, but “SDL.h” instead. This is
much more portable.

-TomT64