简体   繁体   中英

Linux SFML - Cannot Open Shared Object File

Using Linux Mint 18 Cinnamon 64-Bit

I am having issues trying to get SFML to work. I am trying to compile from the command line with g++.

My file is /home/joe/Desktop/SFML/test/main.cpp

My SFML Folder is at /usr/lib/SFML-2.4.1

If I run g++ -c main.cpp -I/usr/lib/SFML-2.4.1/include it compiles fine. Then I run g++ main.o -o sfml-app -L/usr/lib/SFML-2.4.1/lib -lsfml-graphics -lsfml-system -lsfml-window -lsfml-audio This had problems before but after using the -L command it works fine now.

howerver when I run ./sfml-app I get the error ./sfml-app: error while loading shared libraries: libsfml-graphics.so.2.4: cannot open shared object file: No such file or directory

Now in the /usr/lib/SFML-2.4.1/lib directory libsfml-graphics.so.2.4 is a symlink with the following chain( all files in this directory.

libsfml-graphics.so -> libsfml-graphics.so.2.4 -> libsfml-graphics.so.2.4.1

So can anyone explain to me why the object file can not be found? Thanks

The problem you're running into is the fact that you're telling the linker where to find the library files/information, but when running the program your system won't know where to find the shared libraries belonging to SFML.

The quickest fix is to create a small shell script to run your program which sets the environment variable LD_LIBRARY_PATH .

Something like this should work (untested):

#!/usr/bin/bash
LD_LIBRARY_PATH=/usr/lib/SFML-2.4.1/bin ./sfml-app

As an alternative, I'd recommend you compile and install SFML from sources . It's not that complicated. The hardest part is determining all dependencies and get those installed first (preferably using your package manager).

It's also possible to install SFML using apt-get , but I'm not 100% sure their version is up to date: sudo apt-get install libsfml-dev

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM