Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Problem when compiling SFML basic tutorial program in VScode  (Read 3346 times)

0 Members and 1 Guest are viewing this topic.

nbersiller

  • Newbie
  • *
  • Posts: 6
    • View Profile
    • Email
If i try to run the most basic tutorial program listed in the SFML website i get this error.

porcoddio.cpp:1:10: fatal error: include/SFML/Graphics.hpp: No such file or directory
    1 | #include <include/SFML/Graphics.hpp>
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~



Please note that vscode recognizes the path when i type it in, it even suggests me the name of "Graphics.hpp", and there are no squiggly lines underneath #include <include/SFML/Graphics.hpp>in the text editor, it's only when i try to compile it that the terminal gives me this error, and the default path in the intellisense configuration is set to the correct one. I tried everything i could think of, i've been at it for 6 hours. https://stackoverflow.com/questions/72580240/include-sfml-library-in-vscode-sfml-graphics-hpp-no-such-file-or-directory-gcc I also found this question which is similar to mine, and i tried the solution. It didn't work, still the same problem What is this? Here is my code:


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

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11027
    • View Profile
    • development blog
    • Email
Re: Problem when compiling SFML basic tutorial program in VScode
« Reply #1 on: June 28, 2023, 10:42:33 pm »
If you look at any tutorials, documentation or even the StackOverflow answer linked, you'll notice, that they're all using #include <SFML/Graphics.hpp> without the include/ directory.
Have you tried that? ;)

I personally, I highly recommend using the CMake extension with VS Code and something like the CMake SFML Template. Only "downside" is that you need to use the CMake commands from the command palette instead of the run button in VS Code.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

nbersiller

  • Newbie
  • *
  • Posts: 6
    • View Profile
    • Email
Re: Problem when compiling SFML basic tutorial program in VScode
« Reply #2 on: June 29, 2023, 12:19:10 am »
If you look at any tutorials, documentation or even the StackOverflow answer linked, you'll notice, that they're all using #include <SFML/Graphics.hpp> without the include/ directory.
Have you tried that? ;)

I personally, I highly recommend using the CMake extension with VS Code and something like the CMake SFML Template. Only "downside" is that you need to use the CMake commands from the command palette instead of the run button in VS Code.

Yes that's the thing, not only did #include SFML/Graphics without include directory not work (causing the same problem), it also gave me squiggly lines, so idk really

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11027
    • View Profile
    • development blog
    • Email
Re: Problem when compiling SFML basic tutorial program in VScode
« Reply #3 on: June 29, 2023, 12:24:31 am »
So it then tells you it can still not find the header?

What's the contents of your tasks.json?

I still recommend the CMake way mentioned above.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

nbersiller

  • Newbie
  • *
  • Posts: 6
    • View Profile
    • Email
Re: Problem when compiling SFML basic tutorial program in VScode
« Reply #4 on: June 29, 2023, 12:31:18 am »
So it then tells you it can still not find the header?

What's the contents of your tasks.json?

I still recommend the CMake way mentioned above.

With Cmake it still gives the same error
https://ibb.co/Pj3S3J0

PS C:\c++\main> make
g++ -Isrc/include/ -c main.cpp
main.cpp:1:10: fatal error: include/SFML/Graphics.hpp: No such file or directory
    1 | #include <include/SFML/Graphics.hpp>
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
make: *** [Makefile:2: all] Error 1

Also tried "cmake" command and it doesn't recognize it, the extension is installed though.
https://ibb.co/hcbQsYN

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11027
    • View Profile
    • development blog
    • Email
Re: Problem when compiling SFML basic tutorial program in VScode
« Reply #5 on: June 29, 2023, 07:15:28 am »
Stop using include/ for the header it's wrong :D

You need to have CMake itself installed on your system as well. Also read the documentation of the extension to see how to use it

PS C:\c++\main> make
g++ -Isrc/include/ -c main.cpp
There's no linking of SFML, nor does it point to the SFML include directory.
What does your tasks.json look like?
« Last Edit: June 29, 2023, 07:18:16 am by eXpl0it3r »
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

nbersiller

  • Newbie
  • *
  • Posts: 6
    • View Profile
    • Email
Re: Problem when compiling SFML basic tutorial program in VScode
« Reply #6 on: June 29, 2023, 01:59:38 pm »
Stop using include/ for the header it's wrong :D

You need to have CMake itself installed on your system as well. Also read the documentation of the extension to see how to use it

PS C:\c++\main> make
g++ -Isrc/include/ -c main.cpp
There's no linking of SFML, nor does it point to the SFML include directory.
What does your tasks.json look like?

{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "Compile SFML executable",
            "type": "cppbuild",
            "command": "g++",
            "args": [
                "-o",
                "${workspaceFolder}/porcoddio.exe",
                "-IA:/include/SFML/include/",
                "-LA:/lib/",
                "${workspaceFolder}/porcoddio.cpp",
                "-lsfml-graphics",
                "-lsfml-window",
                "-lsfml-system"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            },
        }
    ]
}

Here is the tasks.json

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11027
    • View Profile
    • development blog
    • Email
Re: Problem when compiling SFML basic tutorial program in VScode
« Reply #7 on: June 29, 2023, 02:48:59 pm »
A: do you have a floppy drive? ;D

Quote
IA:/include/SFML/include
This seems odd, why do you have an include folder that contains an SFML folder that includes an include folder?

How are you building and how are you running the application?
« Last Edit: June 30, 2023, 06:05:50 pm by eXpl0it3r »
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

nbersiller

  • Newbie
  • *
  • Posts: 6
    • View Profile
    • Email
Re: Problem when compiling SFML basic tutorial program in VScode
« Reply #8 on: June 29, 2023, 03:09:18 pm »
A: do you have a floppy drive? ;D

Quote
IA:/include/SFML/include
This seems ode, why do you have an include folder that contains an SFML folder that includes an include folder?

How are you building and how are you running the application?

I just extracted the files from the SFML release on github, and created an include folder out of habit where i put the SFML include folder. I'm running the application with the visual studio code run button, nothing much

nbersiller

  • Newbie
  • *
  • Posts: 6
    • View Profile
    • Email
Re: Problem when compiling SFML basic tutorial program in VScode
« Reply #9 on: June 30, 2023, 04:45:56 pm »
A: do you have a floppy drive? ;D

Quote
IA:/include/SFML/include
This seems ode, why do you have an include folder that contains an SFML folder that includes an include folder?

How are you building and how are you running the application?

Please help me. I managed to make cmake work, but how do i use it? I modified my tasks.json file, i don't know if it's better now

{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "Compile SFML executable",
            "type": "cppbuild",
            "command": "g++",
            "args": [
                "-o",
                "${workspaceFolder}/porcoddio.exe",
                "-IC:/Users/user/Documents/c++!/diocaneporcodio/include",
                "-LC:/lib/",
                "${workspaceFolder}/porcoddio.cpp",
                "-lsfml-graphics",
                "-lsfml-window",
                "-lsfml-system"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            },
        }
    ]
}