Link errors with mingw32 on Win98

Hi there.

I’ve just set up mingw32 (gcc 2.95.2) and installed the SDL
development stuff (1.1.3), and I can’t build anything. I
can compile examples fine, but the linking always fails.
I’ve check the web, and searched this mailing list - and
I’ve tried the suggestions I found, to no avail.

This is what I’ve got:

When trying to build an test file:
gcc -I…/include/SDL -lmingw32 -lSDLmain -lSDL -mwindows
sdltest.c

Which spits out this error:
C:\WINDOWS\TEMP\ccNYhegb.o(.text+0xaf):sdltest.c: undefined
reference to `SDL_SetVideoMode’

Now, I’ve tried adding other libraries to the linker
arguments, but it makes to difference. I’ve grepped the
libSDL.a file, and that function does appear to be in
there.

So what am I doing wrong?

If I build the examples that came with the SDL developer
stuff, it fails exactly the same way, but for every SDL_*()
function the program tries to use, yet I can build this
small piece of source fine:

include <stdlib.h>
#include “SDL.h”

main(int argc, char *argv[])
{
if ( SDL_Init(SDL_INIT_AUDIO|SDL_INIT_VIDEO) < 0 )
{
fprintf(stderr, “Unable to init SDL: %s\n”,
SDL_GetError());
exit(1);
}

atexit(SDL_Quit);

}

That will link fine, and run.

Thanks in advance.

You will need to try playing with the linking libraries order on the link
command line. Most notably, a lib required by another lib must be after
it in the linking order.

e.g. -lpng -lz -> In That Order!

There are actually some wierd loops in dependancies that show up from time
to time that require the same library to be in there twice, or so I’ve
heard.

e.g. -lSDLmain -lSDL -lSDLmain (in that order in the link line).–
Brian

On Thu, 8 Jun 2000 kinetik at paradise.net.nz wrote:

Hi there.

I’ve just set up mingw32 (gcc 2.95.2) and installed the SDL
development stuff (1.1.3), and I can’t build anything. I
can compile examples fine, but the linking always fails.
I’ve check the web, and searched this mailing list - and
I’ve tried the suggestions I found, to no avail.

This is what I’ve got:

When trying to build an test file:
gcc -I…/include/SDL -lmingw32 -lSDLmain -lSDL -mwindows
sdltest.c

Which spits out this error:
C:\WINDOWS\TEMP\ccNYhegb.o(.text+0xaf):sdltest.c: undefined
reference to `SDL_SetVideoMode’

Now, I’ve tried adding other libraries to the linker
arguments, but it makes to difference. I’ve grepped the
libSDL.a file, and that function does appear to be in
there.

So what am I doing wrong?

If I build the examples that came with the SDL developer
stuff, it fails exactly the same way, but for every SDL_*()
function the program tries to use, yet I can build this
small piece of source fine:

include <stdlib.h>
#include “SDL.h”

main(int argc, char *argv[])
{
if ( SDL_Init(SDL_INIT_AUDIO|SDL_INIT_VIDEO) < 0 )
{
fprintf(stderr, “Unable to init SDL: %s\n”,
SDL_GetError());
exit(1);
}

atexit(SDL_Quit);
}

That will link fine, and run.

Thanks in advance.

You will need to try playing with the linking libraries
order on the link
command line. Most notably, a lib required by another
lib must be after
it in the linking order.

e.g. -lpng -lz -> In That Order!

Yeah, the dependancies are no problem, the function it
claims doesn’t exist is in libSDL (the last library I have
on the link line).

There are actually some wierd loops in dependancies that
show up from time
to time that require the same library to be in there
twice, or so I’ve
heard.

e.g. -lSDLmain -lSDL -lSDLmain (in that order in the
link line).

Not the problem in this case, I’ve tried all of the
permutations and no luck…

gcc -I…/include/SDL -lmingw32 -lSDLmain -lSDL -mwindows

Add another -lSDL before -lSDLmain and it should work… Oh, and get rid
of -lmingw32.

Dan

gcc -I…/include/SDL -lmingw32 -lSDLmain -lSDL
-mwindows

Add another -lSDL before -lSDLmain and it should work…
Oh, and get rid
of -lmingw32.

Okay, tried that - and it generates more link errors, so I
tried adding the library containing the unreferenced
functions and it still fails.

For example, using the line above, I get:
C:\WINDOWS\TEMP\cc9SIcgb.o(.text+0xaf):sdltest.c: undefined
reference to `SDL_VideoModeOK’

Using “gcc -I…/include/SDL -lSDLmain -lSDL -mwindows” I
get:
C:\WINDOWS\TEMP\ccpRIcgb.o(.text+0x50):sdltest.c: undefined
reference to SDL_Init' C:\WINDOWS\TEMP\ccpRIcgb.o(.text+0x61):sdltest.c: undefined reference toSDL_GetError’
C:\WINDOWS\TEMP\ccpRIcgb.o(.text+0x94):sdltest.c: undefined
reference to SDL_Quit' C:\WINDOWS\TEMP\ccpRIcgb.o(.text+0xaf):sdltest.c: undefined reference toSDL_VideoModeOK’
C:\WINDOWS\TEMP\ccpRIcgb.o(.text+0xc5):sdltest.c: undefined
reference to SDL_GetError' H:\GCC-29~1.2\BIN\..\lib\gcc-lib\i386-mingw32msvc\2.95.2\.. \..\..\..\i386-mingw32msvc\lib\libmingw32.a(main.o)(.text+0 x8e): undefined reference toWinMain at 16’

Adding another -lSDL makes no difference at this point…
so where I was originally is the closest I’ve been to
getting this to link, it seems. I’ve just set up Visual C++
6 and can build the same code with no problems.

Thanks.

Okay, tried that - and it generates more link errors, so I
tried adding the library containing the unreferenced
functions and it still fails.

Which SDL cross-compile archive are you using? Did you build it
yourself?

See ya,
-Sam Lantinga, Lead Programmer, Loki Entertainment Software

Which SDL cross-compile archive are you using? Did you
build it
yourself?

SDL-1.1.3-mingw32, I downloaded the precompiled version…
What do you mean by cross-compile? I’m compiling under
Windows for a Windows target…

Thanks,
Matthew

Which SDL cross-compile archive are you using? Did you
build it
yourself?

SDL-1.1.3-mingw32, I downloaded the precompiled version…
What do you mean by cross-compile? I’m compiling under
Windows for a Windows target…

Thanks,
Matthew

The Windows version of SDL was compiled under Linux using a cross-compiler
http://www.libsdl.org/Xminw32/ so you can use configure, since mingw32 lacks a
good damn bash !

Anyway, try something like that :
"gcc -o yourexe -mwindows
yourobjectfiles.o -lmingw32 -lSDLmain -lSDL -luser32 -lgdi32 -lwinmm -ldxguid"
It’s surely a problem of library precedence, you have to
put -lmingw32 -lSDLmain -lSDL in that order.
If you use any other SDL_libs, put them between -lmingw32 and -lSDLmain (and put
libs like ttf/jpeg/png/z after -lSDL for instance)

Herve PARISSI
"You assume too much" (The Menace Phantom)

----- Original Message -----
From: kinetik@paradise.net.nz ()
To:
Sent: Saturday, June 10, 2000 9:51 AM
Subject: Re: [SDL] Link errors with mingw32 on Win98