首页 > 解决方案 > 我需要帮助在 VSCode 中使用 SFML (Mac) 创建一个窗口

问题描述

好的,我承认我不是最好的编码员,但我正在努力学习。我对 Java 有一点了解,并且想学习 C++ 来扩展我的技能。我想通过使用 SFML 库创建 Chess 来巩固我的 C++ 技能。我从https://github.com/andrew-r-king/sfml-vscode-boilerplate安装了 SFML,然后运行了样板文件附带的 main.cpp,它工作正常。但是我试图将它复制到一个单独的文件中,但是我无法编译它。我正在用 g++ 编译它,但它不起作用。我似乎不知道为什么。

#include <SFML/Graphics.hpp>

int main()
{
    sf::RenderWindow window(sf::VideoMode(512, 512), "Chess by Nabid Kabir", sf::Style::Titlebar | sf::Style::Close);
    
    while (window.isOpen())
    {
        sf::Event e;
        while(window.pollEvent(e))
        {
            if(e.type == e.Closed)
            {
                window.close();
            }
        }
    }
    return 0;
}

这是我尝试构建和运行时遇到的错误

Starting build...
Build finished with errors(s):
Undefined symbols for architecture x86_64:
  "sf::RenderWindow::RenderWindow(sf::VideoMode, sf::String const&, unsigned int, sf::ContextSettings const&)", referenced from:
      _main in chess-e62717.o
  "sf::RenderWindow::~RenderWindow()", referenced from:
      _main in chess-e62717.o
  "sf::String::String(char const*, std::__1::locale const&)", referenced from:
      _main in chess-e62717.o
  "sf::Window::close()", referenced from:
      _main in chess-e62717.o
  "sf::Window::pollEvent(sf::Event&)", referenced from:
      _main in chess-e62717.o
  "sf::VideoMode::VideoMode(unsigned int, unsigned int, unsigned int)", referenced from:
      _main in chess-e62717.o
  "sf::Window::isOpen() const", referenced from:
      _main in chess-e62717.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

The terminal process terminated with exit code: -1.

谁能帮忙,我不太了解配置库,因为这是我的第一次。

标签: c++macosvisual-studio-codewindowsfml

解决方案


推荐阅读