Newbie stuff

Hey all, newbie here with some questions.

First, I have some basic linking questions. What library(s) do I link to for
SDL? I thought it was libSDLmain.a (-lSDLmain) but I’m not certain now.

Second, where do I set the path for shared libs? I tried a demo and it said
it couldn’t find the shared lib libSDL-1-1.so.O, so I guess make install must
have put them in a place different from my installation.

Thanks!

B.

In general you shouldn’t be dealing with library names and the like.
SDL installs a config script called ‘sdl-config’ which you can call
using backticks when you compile things…

gcc -c sdl-config --cflags -o myprog.o myprog.c
gcc -o myprog myprog.o sdl-config --libs

As for the other application not finding the library, perhaps your
LD_LIBRARY_PATH doesn’t contain the path where the SDL libs were
installed, that is all I can think of regarding that.On Sat, 19 Jun 2004 13:23:47 -0700, Brenden wrote:

Hey all, newbie here with some questions.

First, I have some basic linking questions. What library(s) do I link to for
SDL? I thought it was libSDLmain.a (-lSDLmain) but I’m not certain now.

Second, where do I set the path for shared libs? I tried a demo and it said
it couldn’t find the shared lib libSDL-1-1.so.O, so I guess make install must
have put them in a place different from my installation.

Thanks!

B.


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


Paul Richards

Hey all, newbie here with some questions.

First, I have some basic linking questions. What library(s) do I link
to for SDL? I thought it was libSDLmain.a (-lSDLmain) but I’m not
certain now.

As the previous poster said, to get the job done you just have to run:
gcc -o myprog myprog.o sdl-config --libs

But if you are curious and actually want to know, you can just run:
sdl-config --libs

Second, where do I set the path for shared libs? I tried a demo and
it said it couldn’t find the shared lib libSDL-1-1.so.O, so I guess
make install must have put them in a place different from my
installation.

Perhaps you just need to run ldconfig, to update the database for the
runtime linker. If you installed SDL from source, then the shared
library is probably in /usr/local/lib. Make sure this directory is
included in /etc/ld.so.conf so that ldconfig can find it. See the
documentation for the runtime linker (ld.so) for more information.On Sat, 19 Jun 2004 13:23:47 -0700 Brenden wrote:

Magnus Bergman wrote:

Second, where do I set the path for shared libs? I tried a demo and
it said it couldn’t find the shared lib libSDL-1-1.so.O, so I guess
make install must have put them in a place different from my
installation.

Perhaps you just need to run ldconfig, to update the database for the
runtime linker. If you installed SDL from source, then the shared
library is probably in /usr/local/lib. Make sure this directory is
included in /etc/ld.so.conf so that ldconfig can find it. See the
documentation for the runtime linker (ld.so) for more information.

More likely, it’s binary file is quite old and links to a specific
version of SDL (here SDL 1.1).

To see if the binary links to a specific version of SDL, do :
ldd ./mybinary
if it says something like :
libSDL-1.1.so.0 => /usr/lib/libSDL-1.1.so.0
that’s the cause of the problem.

If you can’t recompile it, the easiest fix is to create a symlink :
cd /usr/lib
ln -s libSDL-1.2.so.0 libSDL-1.1.so

Stephane

I am stumped.

I loaded the SDL libraries via RPM.

All SDL header files are in /usr/include/SDL
PATH includes this directory
LD_LIBRARY_PATH variable will not take, no matter if I log
in as root or user - “echo $LD_LIBRARY_PATH” returns blank
whether I export manually or in my .profile

When I try to compile the following code,

#include “SDL.h” /* All SDL App’s need this */
#include <stdio.h>

int main() {

 printf("Initializing SDL.\n");

 /* Initialize defaults, Video and Audio */
 if((SDL_Init(SDL_INIT_VIDEO|SDL_INIT_AUDIO)==-1)) {
     printf("Could not initialize SDL: %s.\n", SDL_GetError());
     exit(-1);
 }

 printf("SDL initialized.\n");

 printf("Quiting SDL.\n");

 /* Shutdown all subsystems */
 SDL_Quit();

 printf("Quiting....\n");

 exit(0);

}

I get the following:

“SDL_Init.c:1:49: SDL.h: No such file or directory”

followed by the usual undeclared function messages that none of the
content funtions of SDL.h are undeclared, etc.

Oh, compile is “gcc SDL_Init.c”

I am looking for a way to either get the libraries recognized via PATH,
or a method of telling the compiler where the libraries are manually. I
tried making a makefile, but am still learning the intricacies of them.
I did try variations on the “inline” methods below, but with no success.

Any help would be greatly appreciated and worth beer(s) to helpers when
next you are in Chicago.

Thanks in advance, and if I missed any part of RTFM, I apologize.

May your good Karma be increased exponentially.

SR

Stephane Marchesin wrote:> Magnus Bergman wrote:

Second, where do I set the path for shared libs? I tried a demo and
it said it couldn’t find the shared lib libSDL-1-1.so.O, so I guess
make install must have put them in a place different from my
installation.

Perhaps you just need to run ldconfig, to update the database for the
runtime linker. If you installed SDL from source, then the shared
library is probably in /usr/local/lib. Make sure this directory is
included in /etc/ld.so.conf so that ldconfig can find it. See the
documentation for the runtime linker (ld.so) for more information.

More likely, it’s binary file is quite old and links to a specific
version of SDL (here SDL 1.1).

To see if the binary links to a specific version of SDL, do :
ldd ./mybinary
if it says something like :
libSDL-1.1.so.0 => /usr/lib/libSDL-1.1.so.0
that’s the cause of the problem.

If you can’t recompile it, the easiest fix is to create a symlink :
cd /usr/lib
ln -s libSDL-1.2.so.0 libSDL-1.1.so

Stephane

Oh, compile is “gcc SDL_Init.c”

I am looking for a way to either get the libraries recognized via PATH,
or a method of telling the compiler where the libraries are manually. I
tried making a makefile, but am still learning the intricacies of them.
I did try variations on the “inline” methods below, but with no success.

The Correct Way ™ to compile SDL programs is to use the sdl-config
program to get the flags to the compiler and the linker. sdl-config
–cflags prints out the compiler flags, and with --libs it prints the
linker flags. So, make your command line like this

gcc -o my_sdl_program SDL_Init.c sdl-config --cflags --libs

Both --cflags and --libs there since you are compiling and linking at
the same time, which is fine for a one-file program. Note that those are
backticks, `, not apostrophes, '. The effect of backticks is that the
shell runs the command in the backticks and replaces it with its output.–
Petri Latvala

Quoth Steven Rummel <steven.rummel at rcn.com>, on 2004-06-23 20:30:22 -0500:

I am stumped.

I loaded the SDL libraries via RPM.
[…]
“SDL_Init.c:1:49: SDL.h: No such file or directory”

Aaaaargh.

This is an FAQ. See “I installed the SDL RPM, but can’t compile SDL
applications” under the Linux section of the SDL FAQ:
http://www.libsdl.org/faq.php?action=listentries&category=3#22.

To quote the answer:
“You need to install the SDL-devel RPM, available from:
http://www.libsdl.org/download.php

As for your compilation command, it’s not guaranteed to work. The
usually correct command for an SDL application with no other modifiers
is:

$CC -o $EXEC $SOURCE sdl-config --cflags --libs

where $CC is the compiler, $EXEC is the output executable, and $SOURCE
is the source file. Note especially the backticks. Those are not single
quotes.

That is, BTW, also an FAQ. See “How do I add SDL to my project?” under
the Linux section of the SDL FAQ for more information:
http://www.libsdl.org/faq.php?action=listentries&category=3#21.

—> Drake Wilson

Petri & Drake -

Thanks for your help and feedback. Petri - your method worked for what I
needed. Both of you got me the key insight - use " ` " not " ’ " .

I appreciate your patience and help.

SR

Petri Latvala wrote:>>Oh, compile is “gcc SDL_Init.c”

I am looking for a way to either get the libraries recognized via PATH,
or a method of telling the compiler where the libraries are manually. I
tried making a makefile, but am still learning the intricacies of them.
I did try variations on the “inline” methods below, but with no success.

The Correct Way ™ to compile SDL programs is to use the sdl-config
program to get the flags to the compiler and the linker. sdl-config
–cflags prints out the compiler flags, and with --libs it prints the
linker flags. So, make your command line like this

gcc -o my_sdl_program SDL_Init.c sdl-config --cflags --libs

Both --cflags and --libs there since you are compiling and linking at
the same time, which is fine for a one-file program. Note that those are
backticks, `, not apostrophes, '. The effect of backticks is that the
shell runs the command in the backticks and replaces it with its output.


Petri Latvala