我的代码:
#include <SFML/Graphics.hpp>
int main()
{
sf::RenderWindow window(sf::VideoMode(800, 600), "SFML window");
while(window.isOpen())
{
sf::Event Event;
while(window.pollEvent(Event))
{
if(Event.type == sf::Event::Closed || Event.key.code == sf::Keyboard::Escape)
window.close();
}
window.display();
}
return 0;
}
我的编译器调用:
g++ main.cpp -framework SFML -lsfml-graphics -lsfml-window -lsfml-system
错误信息:
Undefined symbols for architecture x86_64:
"sf::RenderWindow::RenderWindow(sf::VideoMode, sf::String const&, unsigned int, sf::ContextSettings const&)", referenced from:
_main in cc8BMfpR.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status
RenderWindow 是否在我忘记链接的库中?我假设它在“窗口”中。我正在运行 SFML 2.1 并尝试了各种链接组合,所有这些都给我链接错误。这个链接链给我的错误最少,即 RenderWindow 错误。有人帮我解决这个问题吗?我在这里有点不知所措。我在 mac os 10.8 上运行。
最佳答案
Is RenderWindow in a library I forgot to link? I assumed it was in the 'window' one..
它在图形包中。因此在 sfml-graphics 中。但是您已经链接了那个。但是,您不应该链接 SFML.framework(它只包含头文件)。
如前所述here ,您可以使用框架或动态库。您的程序可以使用以下任一方式编译:
g++ main.cpp -lsfml-graphics -lsfml-window -lsfml-system
或
g++ main.cpp -framework sfml-graphics -framework sfml-window -framework sfml-system
现在,关于Undefined symbols for architecture x86_64 错误,我只能猜测您没有从download page 下载兼容版本。 .如果您想使用 g++,请下载“GCC”版本。
关于c++ - SFML 2.1 RenderWindow 链接错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17910387/