未明确引用sf ::

时间:2017-09-30 07:10:55

标签: c++ linux netbeans makefile undefined-reference

我想用c ++制作gui应用程序,发现SFML是个不错的选择。幸运的是我在Linux上,所以我的系统上已经安装了SFML(2.4)。  所以我开始搜索一些教程,找到了一个简单的窗口。但是当我运行代码时,我得到一个错误,说明未定义的参考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)

我已尝试在谷歌上搜索解决方案,但无法找到任何有效的解决方案。所以我认为一些专家意见会很好。请帮忙。感谢

1 个答案:

答案 0 :(得分:3)

您忘记了与SFML库的链接。这些至少是:

  • SFML图形
  • SFML窗口
  • SFML系统

正如documentation解释的那样,在Linux上可以这样做:

g++ myapp.o -o myapp -lsfml-graphics -lsfml-window -lsfml-system

或者,如果使用IDE,请在链接器设置中将它们指定为附加依赖项。