在使用 XCode 处理 C++11 和 SFML 时遇到链接问题。我已经有了 libc++ 和 C++11 库,但是在使用字符串文字命名窗口时代码出现问题。以前有人遇到过这个并且知道如何解决它吗?谢谢!
错误:
主要.cpp
#include <SFML/Audio.hpp>
#include <SFML/Graphics.hpp>
#include <iostream>
#include <memory>
#include "System.hpp"
int main(int, char const**)
{
std::shared_ptr<System> main;
main.reset(new System());
main->run();
return EXIT_SUCCESS;
}
系统.hpp
#ifndef __AdventuresOfGabe__System__
#define __AdventuresOfGabe__System__
class System
{
public:
System();
void run();
void runEvents();
private:
std::shared_ptr<sf::RenderWindow> _window;
};
#endif /* defined(__AdventuresOfGabe__System__) */
System::System()
{
_window.reset(new sf::RenderWindow(sf::VideoMode(600, 400), "Adventures of Gabe"));
_window->setPosition(sf::Vector2i(400,400));
_window->setFramerateLimit(60);
}
void System::run()
{
while(_window->isOpen())
{
runEvents();
}
}
void System::runEvents()
{
sf::Event event;
while(_window->pollEvent(event) )
{
if( event.type == sf::Event::Closed )
_window->close();
if( (event.type == sf::Event::KeyPressed) && (event.key.code == sf::Keyboard::Escape) )
_window->close();
}
}
最佳答案
A few words about the templates settings. If you choose an incompatible option for C++ Compiler and Standard Library you will end up with linker errors. Make sure you follow this guideline:
- If you downloaded the "GCC" version from the download page, you should select C++98 with GCC and libstdc++ and target 10.5.
- If you downloaded the "Clang" version from the download page, you should select C++11 with Clang and libc++.
因此您需要下载其他版本的 SDK,即 «Clang» 版本。
顺便说一句,您可以使用 std::make_shared
来简化您的代码。
关于c++ - 为 sf::String 使用字符串文字时出现链接器错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18796229/