Can' run program on computer w/o libSDL2 installed

At last I finished my C program which uses SDL for graphics. I installed it on another computer running the same OS (LINUX Ubuntu 14.04) and I get the following error when I try to run it:

error while loading shared libraries: libSDL2-2.0.so.0: cannot open shared object file: No such file or directory

Does that mean I need to install libSDL files in order to run it on the other computer? If so, can you tell me if there are gcc compiler options I can use to make the program stand alone? There must be something I can do to accomplish this.

TIA Bill S.

Hi,

I?m not too familiar with the particular compiler switches you?d need to pass, but in essence, what you are asking for is a statically linked build. Sometimes this can be tricky? but in short, you basically need to compile SDL as a static library, also known as a library archive with the file extension ?.a?. (This might already be built by default, I don?t know off the top ? look in your /usr/local/lib or wherever).

I say this can be tricky, because you have to potentially take into account building the dependent libraries of SDL statically as well, depending on your needs, but at any rate, I?d suggest reading up on the topic, and first try building just SDL statically. Rebuild your project linking to the static SDL library and go from there ? you?ll either have dependencies that also need to be built statically and linked to your project, or you?ll luck out and be OK as-is.

I don?t know the trouble you may be headed into here? I haven?t ever tried this myself with SDL. Hopefully somebody else lurking around will speak up :slight_smile: Good luck!

Cheers,
Jeffrey Carpenter <@Jeffrey_Carpenter>

-------------- next part --------------
A non-text attachment was scrubbed…
Name: smime.p7s
Type: application/pkcs7-signature
Size: 1572 bytes
Desc: not available
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20150408/8a33dfb4/attachment.bin

You might just be able to do a soft link from libSDL2.2.0.so to the .so.0
file. I think that’s right…On 8 Apr 2015 02:50, “bilsch01” wrote:

At last I finished my C program which uses SDL for graphics. I installed
it on another computer running the same OS (LINUX Ubuntu 14.04) and I get
the following error when I try to run it:

error while loading shared libraries: libSDL2-2.0.so.0: cannot open shared
object file: No such file or directory

Does that mean I need to install libSDL files in order to run it on the
other computer? If so, can you tell me if there are gcc compiler options I
can use to make the program stand alone? There must be something I can do
to accomplish this.

TIA Bill S.


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

You can use rpath to instruct the linker to find a bundled libsdl relative
to your executable, or run it from a wrapper script that sets
ld_library_path.

Great care must be taken to avoid linking to distro specific symbols. See
also the steam runtime for an example of linking with controlled
dependencies.On Apr 8, 2015 2:50 AM, “bilsch01” wrote:

At last I finished my C program which uses SDL for graphics. I installed
it on another computer running the same OS (LINUX Ubuntu 14.04) and I get
the following error when I try to run it:

error while loading shared libraries: libSDL2-2.0.so.0: cannot open shared
object file: No such file or directory

Does that mean I need to install libSDL files in order to run it on the
other computer? If so, can you tell me if there are gcc compiler options I
can use to make the program stand alone? There must be something I can do
to accomplish this.

TIA Bill S.


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

You might just be able to do a soft link from libSDL2.2.0.so
to the .so.0 file. I think that’s right…

That won’t work at all if libsdl is just not installed on that system.

You either want static linking, try:
gcc -o bla sdl2-config --cflags -static sdl2-config --static-libs
bla.c
or you bundle libsdl2.so.0 with your application and use RPATH $ORIGIN,
see http://jorgen.tjer.no/post/2014/05/20/dt-rpath-ld-and-at-rpath-dyld/

Cheers,
DanielOn 04/08/2015 05:40 PM, Alex Barry wrote:

On 8 Apr 2015 02:50, “bilsch01” <king621 at comcast.net <mailto:king621 at comcast.net>> wrote:

__
At last I finished my C program which uses SDL for graphics. I
installed it on another computer running the same OS (LINUX Ubuntu
14.04) and I get the following error when I try to run it:

error while loading shared libraries: libSDL2-2.0.so.0: cannot open
shared object file: No such file or directory

Does that mean I need to install libSDL files in order to run it on
the other computer? If so, can you tell me if there are gcc compiler
options I can use to make the program stand alone? There must be
something I can do to accomplish this.

TIA Bill S.

_______________________________________________
SDL mailing list
SDL at lists.libsdl.org <mailto:SDL at lists.libsdl.org>
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Daniel Gibson wrote:> On 04/08/2015 05:40 PM, Alex Barry wrote:

You might just be able to do a soft link from libSDL2.2.0.so
to the .so.0 file. I think that’s right…

That won’t work at all if libsdl is just not installed on that system.

You either want static linking, try:
gcc -o bla sdl2-config --cflags -static sdl2-config --static-libs
bla.c
or you bundle libsdl2.so.0 with your application and use RPATH $ORIGIN,
see http://jorgen.tjer.no/post/2014/05/20/dt-rpath-ld-and-at-rpath-dyld/

Cheers,
Daniel

I tried this: gcc -o graf1 sdl2-config --cflags -static sdl2-config --static-libs graf.c

I got this:

/usr/bin/ld: cannot find -lasound
/usr/bin/ld: cannot find -lpulse-simple
/usr/bin/ld: cannot find -lpulse
/usr/bin/ld: cannot find -lwayland-egl
/usr/bin/ld: cannot find -lts
collect2: error: ld returned 1 exit status

I tried this: gcc -o graf1 sdl2-config --cflags -static sdl2-config --static-libs graf.c

I got this:

/usr/bin/ld: cannot find -lasound
/usr/bin/ld: cannot find -lpulse-simple
/usr/bin/ld: cannot find -lpulse
/usr/bin/ld: cannot find -lwayland-egl
/usr/bin/ld: cannot find -lts
collect2: error: ld returned 1 exit status

On 8 Apr 2015 02:50, “bilsch01” <@bilsch01 mailto:bilsch01> wrote:

__
At last I finished my C program which uses SDL for graphics. I
installed it on another computer running the same OS (LINUX Ubuntu
14.04) and I get the following error when I try to run it:

error while loading shared libraries: libSDL2-2.0.so.0: cannot open
shared object file: No such file or directory

Does that mean I need to install libSDL files in order to run it on
the other computer? If so, can you tell me if there are gcc compiler
options I can use to make the program stand alone? There must be
something I can do to accomplish this.

TIA Bill S.


SDL mailing list
SDL at lists.libsdl.org <mailto:SDL at lists.libsdl.org>
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

this means you’re missing the corresponding -dev packages.
But probably the libSDL2 supplied by distributions is not optimal for
this anyway, as it links against all those libs - if you build it
yourself with default flags, most of the libs will be loaded with
dlopen(), if they’re available, and thus don’t need to be linked against.
When I execute sdl2-config --static-libs from a custom build, I get the
following output:
$ ./sdl2-config --static-libs
-L/tmp/lib -Wl,-rpath,/tmp/lib -lSDL2 -lpthread -Wl,–no-undefined -lm
-ldl -lts -lpthread -lrt

so it only seems to link against things from glibc and SDL2 itself.

Cheers,
DanielOn 04/08/2015 10:38 PM, bilsch01 wrote:

I tried this: gcc -o graf1 sdl2-config --cflags -static sdl2-config --static-libs graf.c

I got this:

/usr/bin/ld: cannot find -lasound
/usr/bin/ld: cannot find -lpulse-simple
/usr/bin/ld: cannot find -lpulse
/usr/bin/ld: cannot find -lwayland-egl
/usr/bin/ld: cannot find -lts
collect2: error: ld returned 1 exit status

I tried this: gcc -o graf1 sdl2-config --cflags -static sdl2-config --static-libs graf.c

I got this:

/usr/bin/ld: cannot find -lasound
/usr/bin/ld: cannot find -lpulse-simple
/usr/bin/ld: cannot find -lpulse
/usr/bin/ld: cannot find -lwayland-egl
/usr/bin/ld: cannot find -lts
collect2: error: ld returned 1 exit status

[quote=“Daniel Gibson”]On 04/08/2015 10:38 PM, bilsch01 wrote:

I tried this: gcc -o graf1 sdl2-config --cflags -static sdl2-config --static-libs graf.c

I got this:

/usr/bin/ld: cannot find -lasound
/usr/bin/ld: cannot find -lpulse-simple
/usr/bin/ld: cannot find -lpulse
/usr/bin/ld: cannot find -lwayland-egl
/usr/bin/ld: cannot find -lts
collect2: error: ld returned 1 exit status

I tried this: gcc -o graf1 sdl2-config --cflags -static sdl2-config --static-libs graf.c

I got this:

/usr/bin/ld: cannot find -lasound
/usr/bin/ld: cannot find -lpulse-simple
/usr/bin/ld: cannot find -lpulse
/usr/bin/ld: cannot find -lwayland-egl
/usr/bin/ld: cannot find -lts
collect2: error: ld returned 1 exit status

if you build it
yourself with default flags, most of the libs will be loaded with
dlopen(), if they’re available, and thus don’t need to be linked against.
When I execute sdl2-config --static-libs from a custom build, I get the
following output:
$ ./sdl2-config --static-libs
-L/tmp/lib -Wl,-rpath,/tmp/lib -lSDL2 -lpthread -Wl,–no-undefined -lm
-ldl -lts -lpthread -lrt

so it only seems to link against things from glibc and SDL2 itself.

Cheers,
Daniel

Thanks for your response. I don’t understand what the output above tells us. How does it tell what files to static link with my program? The file libSDL2.a has hundreds of unrecognized references in it. I am linking with all of the libSDL2 … ‘.a’ files in directory /usr/lib/i386-linux-gnu. I searched some of the unrecognized references and they seem to be in other files in the same directory but I only checked a few of many.

I do have a top level package file for the whole library: libsdl2-2.0-0_2.0.2+dfsg1-3ubuntu1_i386.deb but the file is older than the libraries on my system.
Can you recommend a course of action for me. Please be specific I’m not all that savvy.

  • download libSDL sourcecode
  • extract it
  • go into the extracted directory (in terminal)
  • mkdir mybuild
  • cd mybuild
  • …/configure --prefix=/home/yourname/SDL2/
  • make
  • make install

In /home/yourname/SDL2/ you’ll find an include/ directory with the
headers, a lib/ directory with the dynamic and static libs and a bin/
directory with sdl2-config in it.
Use /home/yourname/SDL2/bin/sdl2-config --cflags and
/home/yourname/SDL2/bin/sdl2-config --static-libs
when compiling to get the needed compilerflags for the build.On 04/09/2015 01:19 AM, bilsch01 wrote:

Thanks for your response. I don’t understand what the output above tells
us. How does it tell what files to static link with my program? The file
libSDL2.a has hundreds of unrecognized references in it. I am linking
with all of the libSDL2 … ‘.a’ files in directory
/usr/lib/i386-linux-gnu. I searched some of the unrecognized references
and they seem to be in other files in the same directory but I only
checked a few of many.

I do have a top level package file for the whole library:
libsdl2-2.0-0_2.0.2+dfsg1-3ubuntu1_i386.deb but the file is older than
the libraries on my system.
Can you recommend a course of action for me. Please be specific I’m not
all that savvy.

I do my release builds on a virtual machine running debian lenny with a
self built GCC 4.8.3 (to be able to use C++11 goods) using a self built SDL
(2.0.3) with --enable-static --disable-shared in configure script, so SDL2
(that is not bundled in debian lenny) can be linked only statically.

I link with --static-libgcc --static-libstdc++ so, since SDL dynamically
loads his dependencies, I run essentially without any external, distro
specific dependency.

The binaries built in this way runs on any linux distro of the last 10
years.On Thu, Apr 9, 2015 at 1:28 AM, Daniel Gibson wrote:

On 04/09/2015 01:19 AM, bilsch01 wrote:

Thanks for your response. I don’t understand what the output above tells
us. How does it tell what files to static link with my program? The file
libSDL2.a has hundreds of unrecognized references in it. I am linking
with all of the libSDL2 … ‘.a’ files in directory
/usr/lib/i386-linux-gnu. I searched some of the unrecognized references
and they seem to be in other files in the same directory but I only
checked a few of many.

I do have a top level package file for the whole library:
libsdl2-2.0-0_2.0.2+dfsg1-3ubuntu1_i386.deb but the file is older than
the libraries on my system.
Can you recommend a course of action for me. Please be specific I’m not
all that savvy.

  • download libSDL sourcecode
  • extract it
  • go into the extracted directory (in terminal)
  • mkdir mybuild
  • cd mybuild
  • …/configure --prefix=/home/yourname/SDL2/
  • make
  • make install

In /home/yourname/SDL2/ you’ll find an include/ directory with the
headers, a lib/ directory with the dynamic and static libs and a bin/
directory with sdl2-config in it.
Use /home/yourname/SDL2/bin/sdl2-config --cflags and
/home/yourname/SDL2/bin/sdl2-config --static-libs
when compiling to get the needed compilerflags for the build.


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


Ing. Gabriele Greco, DARTS Engineering
Tel: +39-0100980150 Fax: +39-0100980184
s-mail: Piazza Della Vittoria 9/3 - 16121 GENOVA (ITALY)

[quote=“Daniel Gibson”]On 04/09/2015 01:19 AM, bilsch01 wrote:

Thanks for your response. I don’t understand what the output above tells
us. How does it tell what files to static link with my program? The file
libSDL2.a has hundreds of unrecognized references in it. I am linking
with all of the libSDL2 … ‘.a’ files in directory
/usr/lib/i386-linux-gnu. I searched some of the unrecognized references
and they seem to be in other files in the same directory but I only
checked a few of many.

I do have a top level package file for the whole library:
libsdl2-2.0-0_2.0.2+dfsg1-3ubuntu1_i386.deb but the file is older than
the libraries on my system.
Can you recommend a course of action for me. Please be specific I’m not
all that savvy.

  • download libSDL sourcecode
  • extract it
  • go into the extracted directory (in terminal)
  • mkdir mybuild
  • cd mybuild
  • …/configure --prefix=/home/yourname/SDL2/
  • make
  • make install

In /home/yourname/SDL2/ you’ll find an include/ directory with the
headers, a lib/ directory with the dynamic and static libs and a bin/
directory with sdl2-config in it.
Use /home/yourname/SDL2/bin/sdl2-config --cflags and
/home/yourname/SDL2/bin/sdl2-config --static-libs
when compiling to get the needed compilerflags for the build._______________________________________________

Thanks for your help. I had problems along the way. SDL site does not offer the source package for linux for download directly. They say use the linux package manager to get and install SDL 2.0.3. I found an older version for download: SDL2-2.0.0.tar.gz from 2013. I uninstalled my up-to-date SDL and then did as you instructed: configure, make, make install with the older version but it got an error during mske install step. Error says:

cannot create regular file ‘/usr/local/lib/libSDL2-2.0.so.0.0.0’: Permission denied

I could not figure this out since there is no other file from any other version of SDL at that path. I did not end up with the exact files and directory structure that you mentioned in your instructions: no bin directory anywhere and no lib directory. AT that point I abandoned the experiment and cleaned out my system and installed the current version of SDL.

Bill S.

Hi,

The error you are getting is because you are trying to install at a path that you do not have the file access permissions required to do so (as a user account, this is usually regarded as a good thing), and thus you would have to issue ?sudo make install? to install using elevated privileges (root / admin account).

But ? it shouldn?t be trying to install to that location, anyway. You don?t see the directory structure that you are expecting because something went wrong at the ?./configure ?prefix=? step. Something caused the custom prefix not to be set. Are you sure that you added a prefix with a valid directory path?

Cheers,
Jeffrey Carpenter <@Jeffrey_Carpenter>

-------------- next part --------------
A non-text attachment was scrubbed…
Name: smime.p7s
Type: application/pkcs7-signature
Size: 1572 bytes
Desc: not available
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20150409/7eafd4c3/attachment.bin

bilsch01 wrote:

SDL site does not offer the source package for linux for download directly.

The source code download is the very first thing on the SDL2 download page. It says “Source Code”.

2015-04-12 7:33 GMT-03:00, Christian Knudsen :

bilsch01 wrote:

SDL site does not offer the source package for linux for download
directly.

The source code download is the very first thing on the SDL2 download page.
It says “Source Code”.

Source package is not the same thing as source archive (although
admittedly if you get the source code you may as well just build it).

[quote=“Daniel Gibson”]On 04/09/2015 01:19 AM, bilsch01 wrote:

Thanks for your response. I don’t understand what the output above tells
us. How does it tell what files to static link with my program? The file
libSDL2.a has hundreds of unrecognized references in it. I am linking
with all of the libSDL2 … ‘.a’ files in directory
/usr/lib/i386-linux-gnu. I searched some of the unrecognized references
and they seem to be in other files in the same directory but I only
checked a few of many.

I do have a top level package file for the whole library:
libsdl2-2.0-0_2.0.2+dfsg1-3ubuntu1_i386.deb but the file is older than
the libraries on my system.
Can you recommend a course of action for me. Please be specific I’m not
all that savvy.

  • download libSDL sourcecode
  • extract it
  • go into the extracted directory (in terminal)
  • mkdir mybuild
  • cd mybuild
  • …/configure --prefix=/home/yourname/SDL2/
  • make
  • make install

In /home/yourname/SDL2/ you’ll find an include/ directory with the
headers, a lib/ directory with the dynamic and static libs and a bin/
directory with sdl2-config in it.
Use /home/yourname/SDL2/bin/sdl2-config --cflags and
/home/yourname/SDL2/bin/sdl2-config --static-libs
when compiling to get the needed compilerflags for the build._______________________________________________
OK Daniel. I got the current source code and followed all your instructions. It’s the last step that’s not working. Maybe I’m not doing it right. I used the two following command lines:

  1. gcc graf.c -o graf1 -lm ‘/home/bill/SDL2/bin/sdl2-config --cflags’ '/home/bill/SDL2/bin/sdl2-config --static-libs ’
  2. gcc graf.c -o graf1 -lm /home/bill/SDL2/bin/sdl2-config --cflags /home/bill/SDL2/bin/sdl2-config --static-libs
    The first says:
    gcc: error: /home/bill/SDL2/bin/sdl2-config --cflags: No such file or directory
    gcc: error: /home/bill/SDL2/bin/sdl2-config --static-libs : No such file or directory
    The second says:
    gcc: error: unrecognized command line option ?–cflags?
    gcc: error: unrecognized command line option ?–static-libs?

Not ‘/home/bill/SDL2/bin/sdl2-config --cflags’ but
/home/bill/SDL2/bin/sdl2-config --cflags

` (backtick) instead of 'On 04/13/2015 10:13 AM, bilsch01 wrote:

OK Daniel. I got the current source code and followed all your
instructions. It’s the last step that’s not working. Maybe I’m not doing
it right. I used the two following command lines:

  1. gcc graf.c -o graf1 -lm ‘/home/bill/SDL2/bin/sdl2-config --cflags’
    ’/home/bill/SDL2/bin/sdl2-config --static-libs ’
  2. gcc graf.c -o graf1 -lm /home/bill/SDL2/bin/sdl2-config --cflags
    /home/bill/SDL2/bin/sdl2-config --static-libs
    The first says:
    gcc: error: /home/bill/SDL2/bin/sdl2-config --cflags: No such file or
    directory
    gcc: error: /home/bill/SDL2/bin/sdl2-config --static-libs : No such file
    or directory
    The second says:
    gcc: error: unrecognized command line option ?–cflags?
    gcc: error: unrecognized command line option ?–static-libs?

[quote=“Daniel Gibson”]On 04/13/2015 10:13 AM, bilsch01 wrote:

OK Daniel. I got the current source code and followed all your
instructions. It’s the last step that’s not working. Maybe I’m not doing
it right. I used the two following command lines:

  1. gcc graf.c -o graf1 -lm ‘/home/bill/SDL2/bin/sdl2-config --cflags’
    ’/home/bill/SDL2/bin/sdl2-config --static-libs ’
  2. gcc graf.c -o graf1 -lm /home/bill/SDL2/bin/sdl2-config --cflags
    /home/bill/SDL2/bin/sdl2-config --static-libs
    The first says:
    gcc: error: /home/bill/SDL2/bin/sdl2-config --cflags: No such file or
    directory
    gcc: error: /home/bill/SDL2/bin/sdl2-config --static-libs : No such file
    or directory
    The second says:
    gcc: error: unrecognized command line option ?–cflags?
    gcc: error: unrecognized command line option ?–static-libs?

Not ‘/home/bill/SDL2/bin/sdl2-config --cflags’ but
/home/bill/SDL2/bin/sdl2-config --cflags

` (backtick) instead of '_______________________________________________
Thanks for your help. The backticks got the program to compile with no problem. But the executable end product has the same problem when run on a computer without libSDL2 installed. It says:
error while loading shared libraries: libSDL2-2.0.so.0: cannot open shared object file: No such file or directory
Apparently the static libraries didn’t get linked in. The new file is only 5 bytes larger than the dynamic link one - which seems odd.

Bill S.

And you also added /home/bill/SDL2/bin/sdl2-config --static-libs ?
Also, make sure there is no “-lSDL2” or similar in the line (which
would add dynamic linkage against sdl2 after all)

Hmm, maybe try “–static” before /home/bill/SDL2/bin/sdl2-config --static-libsOn 04/14/2015 03:05 AM, bilsch01 wrote:

Thanks for your help. The backticks got the program to compile with no
problem. But the executable end product has the same problem when run on
a computer without libSDL2 installed. It says:
error while loading shared libraries: libSDL2-2.0.so.0: cannot open
shared object file: No such file or directory
Apparently the static libraries didn’t get linked in. The new file is
only 5 bytes larger than the dynamic link one - which seems odd.

Bill S.

[quote=“Daniel Gibson”]On 04/14/2015 03:05 AM, bilsch01 wrote:

Thanks for your help. The backticks got the program to compile with no
problem. But the executable end product has the same problem when run on
a computer without libSDL2 installed. It says:
error while loading shared libraries: libSDL2-2.0.so.0: cannot open
shared object file: No such file or directory
Apparently the static libraries didn’t get linked in. The new file is
only 5 bytes larger than the dynamic link one - which seems odd.

Bill S.

And you also added /home/bill/SDL2/bin/sdl2-config --static-libs ?
Also, make sure there is no “-lSDL2” or similar in the line (which
would add dynamic linkage against sdl2 after all)

Hmm, maybe try “–static” before /home/bill/SDL2/bin/sdl2-config --static-libs_______________________________________________
I tried this:
gcc graf.c -o graf1 /home/bill/SDL2/bin/sdl2-config --cflags --static /home/bill/SDL2/bin/sdl2-config --static-libs

I got errors familiar from earlier:
/home/bill/SDL2/lib/libSDL2.a(SDL_dynapi.o): In function `get_sdlapi_entry’:
/home/bill/sdl2src/SDL2-2.0.3/src/dynapi/SDL_dynapi.c:227: warning: Using ‘dlopen’ in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/bin/ld: cannot find -lts
collect2: error: ld returned 1 exit status

Sik wrote:

2015-04-12 7:33 GMT-03:00, Christian Knudsen <@Christian_Knudsen>:

bilsch01 wrote:

SDL site does not offer the source package for linux for download
directly.

The source code download is the very first thing on the SDL2 download page.
It says “Source Code”.

Source package is not the same thing as source archive (although
admittedly if you get the source code you may as well just build it).

Fair enough, but the instruction given in this thread was to “download libSDL sourcecode”.