4 Replies - 2429 Views - Last Post: 12 March 2012 - 07:48 AM Rate Topic: -----

#1 Jgke  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 07-September 11

undefined references, SDL_image, code::blocks

Posted 11 March 2012 - 03:37 AM

I'm currently learning c++ and SDL, using Code::Blocks as an IDE. I'm trying to use the IMG_Load() function, but it gives an 'undefined reference to IMG_Load' error. I guess this is about badly linked SDL_image library. I have the SDL_image.lib listed under 'Linker Settings' at the compiler and debugger settings. SDL_image.h is in the 'include' folder AND the 'SDL' subfolder at my compiler (MinGW).

What now?

Is This A Good Question/Topic? 0
  • +

Replies To: undefined references, SDL_image, code::blocks

#2 r.stiltskin  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1833
  • View blog
  • Posts: 4,927
  • Joined: 27-December 05

Re: undefined references, SDL_image, code::blocks

Posted 11 March 2012 - 08:13 AM

In Project build options/Compiler settings/Other options:
`sdl-config --cflags`


In Project build options/Linker settings/Other linker options:
`sdl-config --libs`


Notice that those marks are "back-ticks", not single quotes. Look above the Tab key on your keyboard.

(And you should delete any other entries that you have made in the Build Options related to SDL.)
Was This Post Helpful? 0
  • +
  • -

#3 Jgke  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 07-September 11

Re: undefined references, SDL_image, code::blocks

Posted 11 March 2012 - 10:40 PM

undefined reference to `IMG_Load'

Didn't work.
Was This Post Helpful? 0
  • +
  • -

#4 Jgke  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 07-September 11

Re: undefined references, SDL_image, code::blocks

Posted 12 March 2012 - 06:47 AM

Okay, and I now reinstalled code::blocks and now everything works. Problem from my end it seems :/
Was This Post Helpful? 0
  • +
  • -

#5 r.stiltskin  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1833
  • View blog
  • Posts: 4,927
  • Joined: 27-December 05

Re: undefined references, SDL_image, code::blocks

Posted 12 March 2012 - 07:48 AM

For the record, I just discovered that `sdl-config --libs` only expands to
-lSDL which isn't enough to link SDL_image.

You have to explicitly add -lSDL_image to Project build options/Linker settings/Link libraries.

In other words, the complete compiler command should be something like this:
gcc -I/usr/include/SDL -lSDL -lSDL_image -o sdl_test sdl_test.c


I'm guessing that the SDL Project Wizard in your reinstalled CodeBlocks did that automatically for you.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1