Link errors

Hey, I’m relatively new to SDL and the concept of linkers. I’m getting a few
link errors while running through the examples in the programming linux games
book. For example:

bash-2.05b$ sdlcc ./alpha-sdl
/tmp/cc6RCJ1O.o(.text+0xa3): In function main': : undefined reference toIMG_Load’
/tmp/cc6RCJ1O.o(.text+0xd0): In function main': : undefined reference toIMG_Load’
/tmp/cc6RCJ1O.o(.text+0xfd): In function main': : undefined reference toIMG_Load’
collect2: ld returned 1 exit status

Here are my includes:
/* Example of alpha blending with SDL. */

#include <SDL/SDL.h>
#include <SDL/SDL_image.h>
#include <stdio.h>
#include <stdlib.h>

and one line where I’m using IMG_Load:
image_with_alpha = IMG_Load(“with-alpha.png”);

And here is the very quick and dirty script I’m using to gcc stuff:
gcc $1.c $2 $3 $4 $5 $6 $7 $8 $9 -o $1 sdl-config --cflags --libs
Yes, I know this line is hideous, it was after midnight, and I just
didn’t want to type a lot when I created it.

I seem to be able to get most things that only rely on SDL/SDL.h to work,
but SDL_image.h seems to hate me…
I can track down most compiler error messages, but I get a little symied when
it comes to linker errors. As far as I can tell from the SDL docs, I should
be able to make that call. Any hints on where I should be looking to correct
this would be appreciated.

Thanks,
Austin

Hey, I’m relatively new to SDL and the concept of linkers.

Sounds like your new to programming.

I’m getting a few
link errors while running through the examples in the programming
linux games
book. For example:

bash-2.05b$ sdlcc ./alpha-sdl
/tmp/cc6RCJ1O.o(.text+0xa3): In function main': : undefined reference toIMG_Load’
/tmp/cc6RCJ1O.o(.text+0xd0): In function main': : undefined reference toIMG_Load’
/tmp/cc6RCJ1O.o(.text+0xfd): In function main': : undefined reference toIMG_Load’
collect2: ld returned 1 exit status

Is SDLCC an alias, shell function, or shell script from the book? If
so, maybe you can do this to link the library that provides the
IMG_Load function, SDL_image.

sdlcc -lSDL_image alpha-sdl

That’s a lowercase l there (as in library.)

If sdlcc isn’t one of those things, then maybe you want to do this:

cc -o program-name main.c sdl-config --cflags --libs -lSDL_image

Maybe you’re not using c, and maybe your source file isn’t called
main.c. Just make the appropriate changes and give it a whirl.On Aug 31, 2004, at 2:58 PM, Austin W. Dunham V wrote:

Here are my includes:
/* Example of alpha blending with SDL. */

#include <SDL/SDL.h>
#include <SDL/SDL_image.h>
#include <stdio.h>
#include <stdlib.h>

and one line where I’m using IMG_Load:
image_with_alpha = IMG_Load(“with-alpha.png”);

And here is the very quick and dirty script I’m using to gcc stuff:
gcc $1.c $2 $3 $4 $5 $6 $7 $8 $9 -o $1 sdl-config --cflags --libs
Yes, I know this line is hideous, it was after midnight, and I just
didn’t want to type a lot when I created it.

I seem to be able to get most things that only rely on SDL/SDL.h to
work,
but SDL_image.h seems to hate me…
I can track down most compiler error messages, but I get a little
symied when
it comes to linker errors. As far as I can tell from the SDL docs, I
should
be able to make that call. Any hints on where I should be looking to
correct
this would be appreciated.

Thanks,
Austin


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

The program is in C, the sdlcc script is a simple/ugly bash script.

Yes, new to C programming and how C does shared libs.

Adding -lSDL_image did allow me to compile, thanks Donny.

Running into a problem after it compiles though, SDL simply won’t initialize.

    /* Initialize SDL's video system and check for errors. */
    if (SDL_Init(SDL_INIT_VIDEO) == 0)
    {
            printf("Unable to initialize SDL: %s\n", SDL_GetError());
            return 1;
    }

Comes back with:

bash-2.05b$ ./alpha-sdl
Unable to initialize SDL:
bash-2.05b$

No error at all to hint at why.

I’m guessing my lib paths are messed up, and I’ll look into them. If that
doesn’t seem right, holler.

Thanks again,
AustinOn Tuesday 31 August 2004 03:15 pm, Donny Viszneki wrote:

On Aug 31, 2004, at 2:58 PM, Austin W. Dunham V wrote:

Hey, I’m relatively new to SDL and the concept of linkers.

Sounds like your new to programming.

I’m getting a few
link errors while running through the examples in the programming
linux games
book. For example:

bash-2.05b$ sdlcc ./alpha-sdl

/tmp/cc6RCJ1O.o(.text+0xa3): In function main': : undefined reference toIMG_Load’

/tmp/cc6RCJ1O.o(.text+0xd0): In function main': : undefined reference toIMG_Load’

/tmp/cc6RCJ1O.o(.text+0xfd): In function main': : undefined reference toIMG_Load’

collect2: ld returned 1 exit status

Is SDLCC an alias, shell function, or shell script from the book? If
so, maybe you can do this to link the library that provides the
IMG_Load function, SDL_image.

sdlcc -lSDL_image alpha-sdl

That’s a lowercase l there (as in library.)

If sdlcc isn’t one of those things, then maybe you want to do this:

cc -o program-name main.c sdl-config --cflags --libs -lSDL_image

Maybe you’re not using c, and maybe your source file isn’t called
main.c. Just make the appropriate changes and give it a whirl.

Here are my includes:
/* Example of alpha blending with SDL. */

#include <SDL/SDL.h>
#include <SDL/SDL_image.h>
#include <stdio.h>
#include <stdlib.h>

and one line where I’m using IMG_Load:
image_with_alpha = IMG_Load(“with-alpha.png”);

And here is the very quick and dirty script I’m using to gcc stuff:
gcc $1.c $2 $3 $4 $5 $6 $7 $8 $9 -o $1 sdl-config --cflags --libs
Yes, I know this line is hideous, it was after midnight, and I just
didn’t want to type a lot when I created it.

I seem to be able to get most things that only rely on SDL/SDL.h to
work,
but SDL_image.h seems to hate me…
I can track down most compiler error messages, but I get a little
symied when
it comes to linker errors. As far as I can tell from the SDL docs, I
should
be able to make that call. Any hints on where I should be looking to
correct
this would be appreciated.

Thanks,
Austin


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

That’s because SDL_Init returns 0 if everything went well. You can check
the page for SDL_Init in the manual at
http://www.libsdl.org/cgi/docwiki.cgi/, or at the old documentation
project site at http://sdldoc.csn.ul.ie/.

// MartinOn Tue, 31 Aug 2004, Austin W. Dunham V wrote:

   /* Initialize SDL's video system and check for errors. */
   if (SDL_Init(SDL_INIT_VIDEO) == 0)
   {
           printf("Unable to initialize SDL: %s\n", SDL_GetError());
           return 1;
   }

Yeah, sorry, stupid mistake there. == rather than != .
Sorry 'bout that.

Thanks for your help,
AustinOn Tuesday 31 August 2004 04:26 pm, Martin Storsj? wrote:

On Tue, 31 Aug 2004, Austin W. Dunham V wrote:

   /* Initialize SDL's video system and check for errors. */
   if (SDL_Init(SDL_INIT_VIDEO) == 0)
   {
           printf("Unable to initialize SDL: %s\n", SDL_GetError());
           return 1;
   }

That’s because SDL_Init returns 0 if everything went well. You can check
the page for SDL_Init in the manual at
http://www.libsdl.org/cgi/docwiki.cgi/, or at the old documentation
project site at http://sdldoc.csn.ul.ie/.

// Martin

The program works now!

Thanks!

Hi,

Try changing your compile script to

gcc $1.c $2 $3 $4 $5 $6 $7 $8 $9 -o $1 -lSDL_image sdl-config --cflags --libs

The -lSDL_image tells gcc to link your program with the sdl image library.
Hope that works.

JosiahOn Tue, 31 Aug 2004 14:58:29 -0400, Austin W. Dunham V wrote:

Hey, I’m relatively new to SDL and the concept of linkers. I’m getting a few
link errors while running through the examples in the programming linux games
book. For example:

bash-2.05b$ sdlcc ./alpha-sdl
/tmp/cc6RCJ1O.o(.text+0xa3): In function main': : undefined reference toIMG_Load’
/tmp/cc6RCJ1O.o(.text+0xd0): In function main': : undefined reference toIMG_Load’
/tmp/cc6RCJ1O.o(.text+0xfd): In function main': : undefined reference toIMG_Load’
collect2: ld returned 1 exit status

Here are my includes:
/* Example of alpha blending with SDL. */

#include <SDL/SDL.h>
#include <SDL/SDL_image.h>
#include <stdio.h>
#include <stdlib.h>

and one line where I’m using IMG_Load:
image_with_alpha = IMG_Load(“with-alpha.png”);

And here is the very quick and dirty script I’m using to gcc stuff:
gcc $1.c $2 $3 $4 $5 $6 $7 $8 $9 -o $1 sdl-config --cflags --libs
Yes, I know this line is hideous, it was after midnight, and I just
didn’t want to type a lot when I created it.

I seem to be able to get most things that only rely on SDL/SDL.h to work,
but SDL_image.h seems to hate me…
I can track down most compiler error messages, but I get a little symied when
it comes to linker errors. As far as I can tell from the SDL docs, I should
be able to make that call. Any hints on where I should be looking to correct
this would be appreciated.

Thanks,
Austin


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

Whoops! too late oh well glad you got it working!

JosiahOn Tue, 31 Aug 2004 20:16:53 -0500, Josiah Gordon <@Josiah_Gordon> wrote:

Hi,

Try changing your compile script to

gcc $1.c $2 $3 $4 $5 $6 $7 $8 $9 -o $1 -lSDL_image sdl-config --cflags --libs

The -lSDL_image tells gcc to link your program with the sdl image library.
Hope that works.

Josiah

On Tue, 31 Aug 2004 14:58:29 -0400, Austin W. Dunham V wrote:

Hey, I’m relatively new to SDL and the concept of linkers. I’m getting a few
link errors while running through the examples in the programming linux games
book. For example:

bash-2.05b$ sdlcc ./alpha-sdl
/tmp/cc6RCJ1O.o(.text+0xa3): In function main': : undefined reference toIMG_Load’
/tmp/cc6RCJ1O.o(.text+0xd0): In function main': : undefined reference toIMG_Load’
/tmp/cc6RCJ1O.o(.text+0xfd): In function main': : undefined reference toIMG_Load’
collect2: ld returned 1 exit status

Here are my includes:
/* Example of alpha blending with SDL. */

#include <SDL/SDL.h>
#include <SDL/SDL_image.h>
#include <stdio.h>
#include <stdlib.h>

and one line where I’m using IMG_Load:
image_with_alpha = IMG_Load(“with-alpha.png”);

And here is the very quick and dirty script I’m using to gcc stuff:
gcc $1.c $2 $3 $4 $5 $6 $7 $8 $9 -o $1 sdl-config --cflags --libs
Yes, I know this line is hideous, it was after midnight, and I just
didn’t want to type a lot when I created it.

I seem to be able to get most things that only rely on SDL/SDL.h to work,
but SDL_image.h seems to hate me…
I can track down most compiler error messages, but I get a little symied when
it comes to linker errors. As far as I can tell from the SDL docs, I should
be able to make that call. Any hints on where I should be looking to correct
this would be appreciated.

Thanks,
Austin


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