[英]Linux SFML - Cannot Open Shared Object File
Using Linux Mint 18 Cinnamon 64-Bit 使用Linux Mint 18 Cinnamon 64位
I am having issues trying to get SFML to work. 我在尝试使SFML工作时遇到问题。 I am trying to compile from the command line with g++.
我正在尝试使用g ++从命令行进行编译。
My file is /home/joe/Desktop/SFML/test/main.cpp
我的文件是
/home/joe/Desktop/SFML/test/main.cpp
My SFML Folder is at /usr/lib/SFML-2.4.1
我的SFML文件夹位于
/usr/lib/SFML-2.4.1
If I run g++ -c main.cpp -I/usr/lib/SFML-2.4.1/include
it compiles fine. 如果我运行
g++ -c main.cpp -I/usr/lib/SFML-2.4.1/include
则可以正常编译。 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. 然后我运行
g++ main.o -o sfml-app -L/usr/lib/SFML-2.4.1/lib -lsfml-graphics -lsfml-system -lsfml-window -lsfml-audio
在使用-L命令现在可以正常工作。
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
但是,当我运行
./sfml-app
时,出现错误./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. 现在,在
/usr/lib/SFML-2.4.1/lib
目录中,libsfml-graphics.so.2.4是带有以下链的符号链接(此目录中的所有文件。
libsfml-graphics.so -> libsfml-graphics.so.2.4 -> libsfml-graphics.so.2.4.1 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. 您遇到的问题是您告诉链接器在哪里可以找到库文件/信息,但是在运行程序时,系统将不知道在哪里可以找到属于SFML的共享库。
The quickest fix is to create a small shell script to run your program which sets the environment variable LD_LIBRARY_PATH
. 最快的解决方法是创建一个小的Shell脚本来运行您的程序,该脚本会设置环境变量
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 . 作为替代方案,我建议您从source编译并安装SFML 。 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
也可以使用
apt-get
安装SFML,但我不能100%确定其版本是最新的: sudo apt-get install libsfml-dev
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.