0

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.

  • you need to link the libraries to your project – Nasrat Takoor Jan 06 '21 at 04:46
  • how do I do that? I'm using the #include but from what I can tell you need to do more for c++. – nabidkabir Jan 06 '21 at 05:40
  • A #include just tells the compiler to add a library with that name. However the compiler may not know where that is. It searches some default locations, however it seems that your library isn't in one of those locations. See https://stackoverflow.com/a/6141166 – darkspine Jan 06 '21 at 06:32

0 Answers0