cómo instalar la biblioteca c en Linux (en particular, SDL_image)

What is the general approach to installing c libraries on Linux?

In particular, I would like to install este library, with the objective to compile this:

#include <SDL_image.h> // it errs that it does not recognize this

int main()
{
}

Lo que he intentado:

  • get a binary from aquí
  • ponlo adentro /etc/usr/clibs
  • added this path to /etc/ld.so.conf

=> FAILED. still failing to compile my file.

I installed the rpm from aquí

=> FAILED, still failing to compile

I tried building from source: Upon running configure, it said this:

checking for sdl-config... no
checking for SDL - version >= 1.2.10... no
*** The sdl-config script installed by SDL could not be found
*** If SDL was installed in PREFIX, make sure PREFIX/bin is in
*** your path, or set the SDL_CONFIG environment variable to the
*** full path to sdl-config.

I don't understand, it expects a script for installing whose presence there is the result of an installation...

I don't know what to try anymore... I've spent a lot of time trying to figure this out, so if someone could just give me a solution with do this and that, it would be great. An answer to the general question would be a great bonus.

Gracias.

preguntado el 24 de agosto de 12 a las 04:08

3 Respuestas

In most Linux distributions, there are prepared packages available with the SDL libraries. On Debian and Ubuntu, you can simply sudo apt-get install libsdl-image1.2-dev. In Red Hat, Fedora, and CentOS, you can do sudo yum install SDL_image-devel.

You can get the correct flags for the compiler using sdl-config. configure script is the “automated” tool for discovering the correct flags, but it is pretty compilicated. If you haven't used C libraries before, it isn't terribly obvious. The -I flag adds a directory to the search path for #include directivas. La -L flag adds a directory to the search path for libraries and -l tries to add a library to the program. Compiling C happens in two steps, compiling and linking. Compiling only looks at header files (.h files) and only cares about -I directives; it output object code (.o files). Linking only cares about -L y -l options and attempts to resolve the symbols in the object code. Typically, libraries live in /lib y /usr/lib and headers live in /usr/include. However, headers are often broken out into separate subdirectories and thus require more specific -I directives. Some programs started to include foo-config programs that included the proper directives to compile against the library. pkg-config is a generic version used by many libraries, especially ones related to GNOME.

This is all very different from other languages which typically a) just use sources for libraries (e.g., PERL, Python) or b) have an executable format that contains all the information needed for compilation (e.g., Java, C#).

Respondido 26 ago 12, 02:08

I installed the packages as mentioned, an when i try to compile that simple example with just including the header it complains about it not existing. Is there any solution to this? Am i completely stupid or is the process of installing and using a c library extremely cumbersome? are there no automated tools for this? - androide

sdl-config would be present as the result of installing libsdl, which you must do before you install libsdl-image.

Why don't you install the packages provided with your distribution?

Respondido 24 ago 12, 04:08

i did follow your instructions and installed the package. however, when compiling i still get errors. it is not aware of the header file. see my reply above. - androide

From the story you've told so far, you made one attempt to install an rpm from a third-party source, and one attempt to compile a library yourself, both of which failed. Remnants of those failed attempts may be preventing things from working properly. I suggest you take a deep breath and rewrite your question from scratch, and include more details. Don't just say "I get errors". show them! - alan curry

i have cleared the remnants of the old packages and installed the proper ones. I have managed to compile my simple code and run it( see my answer below). (thanks for the help) - androide

Solution: my currently installed packages are:

libsdl1.2debian

libsdl-image1.2

libsdl1.2-dev

libsdl-image1.2-dev

i can compile and run the following code:

#include <SDL_image.h>
#include <math.h>
#include <stdio.h>

int main()
{
  int x = sqrt(4);
  SDL_Surface* s = IMG_Load("foo");
  printf("%d %d", x, s);
  return 0;
}

~

con el comando:

gcc libTest.c `sdl-config --cflags` -Wall -O6 -g -O2   -lSDL_image

(I nicked it from somewhere, I don't really understand it)

Respondido 25 ago 12, 23:08

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.