使用 gcc 链接到库时出现问题
我今天从头开始安装了 SFML,这样我就可以开发游戏了。我下载了源代码,运行 sudo make install,尝试编译我的一个旧项目,但无法正确链接。因此,我尝试运行一个更简单的项目:教程中的示例之一。我尝试专门编译 这个 ,但我得到了这些错误:
g++ -o atest test.cpp -lsfml-graphics -lsfml-window -lsfml-system /tmp/ccaa86fR.o: In function `main':
test.cpp:(.text+0x1d2): undefined reference to `gluPerspective'
collect2: ld returned 1 exit status
make: *** [test] Error 1
尝试一个更简单的项目,初始教程,我在编译时没有遇到问题。但是,当我尝试运行它时,出现此错误:
./atest: error while loading shared libraries: libsfml-graphics.so.1.6: cannot open shared object file: No such file or directory
我检查过,文件确实安装到了 /usr/local/lib/ ,据我所知,这是它们应该去的地方。我在这里做错了什么?
I installed SFML from scratch today so I could work on a game. I downloaded the source, ran sudo make install
, tried compiling one of my old projects, and I couldn't get it to link properly. So I tried running a simpler project: one of the samples in the tutorials. I tried to compile this one specifically, but I get these errors:
g++ -o atest test.cpp -lsfml-graphics -lsfml-window -lsfml-system /tmp/ccaa86fR.o: In function `main':
test.cpp:(.text+0x1d2): undefined reference to `gluPerspective'
collect2: ld returned 1 exit status
make: *** [test] Error 1
Trying an even simpler project, the one in the initial tutorial, I don't run into problems compiling. However, when I try to run it, I get this error:
./atest: error while loading shared libraries: libsfml-graphics.so.1.6: cannot open shared object file: No such file or directory
I checked, and the files did install to /usr/local/lib/ which is where they're supposed to go as far as I know. What am I doing wrong here?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
-lGLU
应该修复第一个错误,对于第二个错误,请确保/usr/local/lib/
位于您的 ldconfig 搜索路径中 (/etc/ld. so.conf
和/etc/ld.so.conf.d/*
在 Ubuntu 下),并且您运行了 ldconfig:sudo ldconfig -v
然后尝试运行再次。另请参阅
man ldconfig
-lGLU
should fix the first error and for the second one make sure/usr/local/lib/
is in your ldconfig search path (/etc/ld.so.conf
and/etc/ld.so.conf.d/*
under Ubuntu) and that you ran ldconfig:sudo ldconfig -v
then try running again.see also
man ldconfig