Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

libSDL2-2.0.so.0: cannot open shared object file

I'm trying to build the SDL library from the source code. I've downloaded the compressed file (i.e. SDL2-2.0.3.tar.gz) and extracted it. I don't want to install the files in /usr/local. According to this link, I need to change the configure

The last command says "sudo" so we can write it to /usr/local (by default). You can change this to a different location with the --prefix option to the configure script. In fact, there are a LOT of good options you can use with configure! Be sure to check out its --help option for details.

This is what I've done.

mkdir build
cd build
../configure
make
sudo make install

In install folder that I've created are the following files

share 
lib
include 
bin

Now I would like to run the test files. I've picked this testatomic.c and this is the command line gcc testatomic.c -o test -I/home/xxxx/Desktop/SDL2-2.0.3/install/include/SDL2 -L/home/xxxx/Desktop/SDL2-2.0.3/install/lib -lSDL2 -lSDL2main

I get this error

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

In lib, these are the files

enter image description here

Where is the shared object file?

like image 232
CroCo Avatar asked Dec 09 '22 03:12

CroCo


1 Answers

You're getting error when running resulting program because system's dynamic linker cannot find required library. Program requires libSDL2-2.0.so.0, linker looks for it in system-defined directories (/lib, /usr/lib, ..., - defined in /etc/ld.so.conf), but finds none - hence an error.

To inform linker where you want it to look for libraries, you can define LD_LIBRARY_PATH environment variable, e.g. in your case:

export LD_LIBRARY_PATH="$HOME/Desktop/SDL2-2.0.3/install/lib"
./test

Other ways is installing libraries in standard location, defining LD_LIBRARY_PATH in your .bashrc (or whatever shell you use), or using rpath, e.g. adding -Wl,-rpath=$HOME/Desktop/SDL2-2.0.3/install/lib at the end of your compilation line.

like image 95
keltar Avatar answered Dec 11 '22 11:12

keltar