Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
334 views
in Technique[技术] by (71.8m points)

c++ - I need help creating a window in VSCode using SFML (Mac)

Ok I'll admit I am not the best coder but I am trying to learn. I know a good bit of Java and wanted to learn C++ to expand my repertoire. I want to solidify my skills in C++ by creating Chess using the SFML library. I installed SFML from https://github.com/andrew-r-king/sfml-vscode-boilerplate and I ran the main.cpp that came with the boilerplate, it worked. However I am trying to replicate it in a separate file however I can't get it to compile. I am compiling it with g++, and it doesn't work. I don't seem to know why.

#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;
}

this is the error I get when I try to build and run

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.

Can anyone help, I don't really understand configuring libraries that well as this is my first time.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...