c++ - 为 sf::String 使用字符串文字时出现链接器错误

标签 c++ xcode macos linker-errors sfml

在使用 XCode 处理 C++11 和 SFML 时遇到链接问题。我已经有了 libc++ 和 C++11 库,但是在使用字符串文字命名窗口时代码出现问题。以前有人遇到过这个并且知道如何解决它吗?谢谢!

错误: Error

主要.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();
    }
}

最佳答案

引用official tutorial ,

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/

相关文章:

ios - 禁用/启用 UIButton

c++ - 我可以让 MoveWindow 使用 Windows 10 中的屏幕坐标吗? C++

c++ - OpenCV3 - 访问标签质心

ios - NSNotification 没有调用@selector 方法

node.js - Gradle "... occurred starting process ' 命令 'npm' '"在 Mac 上

macos - 为什么 CGContextShowGlyphsAtPositions() 不起作用,而 CGContextShowGlyphsAtPoint() 起作用?

java - 在 libfontmanager.dylib 中将 OpenJDK9 与 FreeType @ref 捆绑在一起

c++ - 从基类中选择子类......可能吗?

c++ - 为什么 std::shared_ptr 提供 operator<<?

ios - 转换为最新语法时出现错误 "swiftc failed with exit code 1"