What is the general approach to installing c libraries on Linux?
In particular, I would like to install this library, with the objective to compile this:
#include <SDL_image.h> // it errs that it does not recognize this
int main()
{
}
What I have tried:
/etc/usr/clibs
/etc/ld.so.conf
=> FAILED. still failing to compile my file.
I installed the rpm from here
=> 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.
Thanks.
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
. The 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
directives. The -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
and -l
options and attempts to resolve the symbols in the object code. Typically, libraries live in /lib
and /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#).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With