未定义的引用sf ::
问题描述:
我想在C++中制作gui应用程序,并发现SFML是一个不错的选择。幸运的是,我在Linux上,所以SFML(2.4)已经安装在我的系统上。 所以我开始寻找一些教程,并找到一个简单的窗口。但是当我运行的代码时,我得到一个错误,说未定义的参考sf::(我使用的功能)。这里是代码未定义的引用sf ::
#include <SFML/Graphics.hpp>
int main(void)
{
sf::RenderWindow window(sf::VideoMode(640,480),"SFML working");
return 0;
}
这里是错误日志。
cd '/home/jasper/NetBeansProjects/SFML'
/usr/bin/make -f Makefile CONF=Debug
"/usr/bin/make" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf
make[1]: Entering directory '/home/jasper/NetBeansProjects/SFML'
"/usr/bin/make" -f nbproject/Makefile-Debug.mk dist/Debug/GNU-Linux/sfml
make[2]: Entering directory '/home/jasper/NetBeansProjects/SFML'
mkdir -p dist/Debug/GNU-Linux
g++ -o dist/Debug/GNU-Linux/sfml build/Debug/GNU-Linux/main.o
build/Debug/GNU-Linux/main.o: In function `main':
/home/jasper/NetBeansProjects/SFML/main.cpp:6: undefined reference to `sf::String::String(char const*, std::locale const&)'
/home/jasper/NetBeansProjects/SFML/main.cpp:6: undefined reference to `sf::VideoMode::VideoMode(unsigned int, unsigned int, unsigned int)'
/home/jasper/NetBeansProjects/SFML/main.cpp:6: undefined reference to `sf::RenderWindow::RenderWindow(sf::VideoMode, sf::String const&, unsigned int, sf::ContextSettings const&)'
/home/jasper/NetBeansProjects/SFML/main.cpp:6: undefined reference to `sf::RenderWindow::~RenderWindow()'
collect2: error: ld returned 1 exit status
nbproject/Makefile-Debug.mk:62: recipe for target 'dist/Debug/GNU-Linux/sfml' failed
make[2]: *** [dist/Debug/GNU-Linux/sfml] Error 1
make[2]: Leaving directory '/home/jasper/NetBeansProjects/SFML'
nbproject/Makefile-Debug.mk:59: recipe for target '.build-conf' failed
make[1]: *** [.build-conf] Error 2
make[1]: Leaving directory '/home/jasper/NetBeansProjects/SFML'
nbproject/Makefile-impl.mk:39: recipe for target '.build-impl' failed
make: *** [.build-impl] Error 2
BUILD FAILED (exit value 2, total time: 172ms)
我试过在谷歌搜索解决方案,但找不到任何有效的。所以我认为一些专家意见会很好。请帮助。谢谢
答
您忘记了链接到SFML库。这些都是至少:
- SFML图形
- SFML窗口
- SFML系统
随着documentation解释说,在Linux上也可以这样做:
g++ myapp.o -o myapp -lsfml-graphics -lsfml-window -lsfml-system
或者如果使用IDE,请在链接器设置中将它们指定为附加依赖项。
可能重复[什么是未定义的引用/未解析的外部符号错误,以及如何解决它?](https://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-外部符号错误和怎么办我修复) – arrowd
注意:''主要'声明中的'void'是一个C-ism,并且在C++中完全没有意义(但是无害) - 只是删除它并使用' int main()'。 –