0

I cannot find anything that works, and I don't know where to go. The task is quite simple, to just include SFML as a library in my C++ file, but every time I try, I get some sort of error. I am using the sample code from SFML:

#include <SFML/Graphics.hpp>

int main()
{
    sf::RenderWindow window(sf::VideoMode(200, 200), "SFML works!");
    sf::CircleShape shape(100.f);
    shape.setFillColor(sf::Color::Green);

    while (window.isOpen())
    {
        sf::Event event;
        while (window.pollEvent(event))
        {
            if (event.type == sf::Event::Closed)
                window.close();
        }

        window.clear();
        window.draw(shape);
        window.display();
    }

    return 0;
}

And this is my c_cpp_properties.json file:

{
    "configurations": [
        {
            "name": "Win32",
            "includePath": [
                "${workspaceFolder}/**",
                "C:\\SFML-2.5.1\\include"

            ],
            "defines": [
                "_DEBUG",
                "UNICODE",
                "_UNICODE"
            ],
            "compilerPath": "C:\\mingw64\\bin\\gcc.exe",
            "cStandard": "gnu17",
            "cppStandard": "gnu++17",
            "intelliSenseMode": "windows-gcc-x64"
        }
    ],
    "version": 4
}

It seems so simple, and yet I just can't figure out what I'm doing wrong. I am using MinGW 64 bit, and the matching SFML version. I am coding in VSCode with extensions such as the C/C++ extension and code-runner (have tried to compile manually as well). I have added both the MinGW64 and SFML bin path to Enviroment variables path. I am new to C++ (Python earlier).

Edit

To answer some questions, the directory does include the correct files, which is why I am so confused. And I tried to switch the \ for /, but didn't work:/. And the error (embarrassing I forgot it) is:

testing.cpp:1:10: fatal error: SFML/Graphics.hpp: No such file or directory
halfer
  • 19,824
  • 17
  • 99
  • 186
  • First thought: does your directory ```C:\\SFML-2.5.1\\include``` have nested directory named ```SFML```, which contains ```Graphics.hpp``` file? Second thought: try to replace every ```\\``` with ``/`` in include path – Deumaudit Jun 01 '22 at 15:49
  • Could you quote the compiler error message without your rewording "C++ unable to find folder/file in #include (SFML)". – 273K Jun 01 '22 at 15:53
  • I think you need to edit settings.json and `code-runner.executorMap` but I don't use code-runner. This answer shows how to add additional cpp files instead of that you can add an include path for your compiler: [https://stackoverflow.com/a/57502607/487892](https://stackoverflow.com/a/57502607/487892) – drescherjm Jun 01 '22 at 16:00

0 Answers0