Author Topic: Installing libraries  (Read 14758 times)

XP15EF

  • Guest
Installing libraries
« on: April 01, 2010, 09:34:12 pm »
Hi,

I use codeblocks under OpenSuse-11.2.

I am learning how to program C and use SDL.
SDL was installed and in Yast, I can see :
libSDL-1.2.13 and its devel,
libSDL_image-1.2.7 and its devel.

In Codeblocks, through Project/Build options/Linker settings tab, I added
/usr/include/SDL/SDL.h
/usr/include/SDL/SDL_image.h

My program starts with
#include <stdio.h>
#include <stdlib.h>
#include </usr/include/SDL/SDL.h>
#include </usr/include/SDL/SDL_image.h>

When it comes to
flower=IMG_Load ("flower.png");
I get the error
"undefined reference to 'IMG_Load' "
which means, I think, that SDL_image library is not found.

I don't understand why.
(there is no SDL_image.lib on my system. Is this normal?)

Any hint?

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7678
    • My Best Post
Re: Installing libraries
« Reply #1 on: April 01, 2010, 10:15:11 pm »
Hint:

Compiler uses .h files.

Linker uses other files varies per Operating System. libm.so or libm.a etc. [libm.lib under MS Windows]
m is the math library needed for many c programs.

The "undefined reference" is 99.9% of the time an linker error.

In Code::Blocks it is best to add the library names without the path to the library list.
Note, it is normal to leave off the extension and the lib prefix.
Then, add the search path for the linker.

Note: This is an basic programming info; so the thread may be locked for violating site guidelines.

Tim S.

« Last Edit: April 01, 2010, 10:22:53 pm by stahta01 »
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7678
    • My Best Post
Re: Installing libraries
« Reply #2 on: April 01, 2010, 10:18:06 pm »
I don't understand why.
(there is no SDL_image.lib on my system. Is this normal?)

Unless you are using Visual Studio under Linux; Linux does NOT use .lib extension. MS Windows does.

Tim S.
« Last Edit: April 01, 2010, 10:19:58 pm by stahta01 »
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7678
    • My Best Post
Re: Installing libraries
« Reply #3 on: April 01, 2010, 10:25:01 pm »
As I suggest to ALL newbies; turn on FULL Compiler Logging

http://wiki.codeblocks.org/index.php?title=FAQ#Q:_How_do_I_troubleshoot_an_compiler_problem.3F

And, post questions not related to Code::Blocks on sites that support beginners questions.

Tim S.
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org