4

I'm running into problem after problem with SFML, but hopefully it will be worth it in the end.

Here's the error:

fatal error: SFML/Graphics.hpp : No such file or directory

and the code:

#include < SFML/Graphics.hpp >
#include < SFML/Window.hpp >

int main(){
sf::RenderWindow Window;
Window.create(sf::VideoMode(800, 600), "SFML");

while(Window.isOpen()){
    sf::Event Event;
    while(Window.pollEvent(Event)){
        if(Event.type == sf::Event::Closed)
            Window.close();
    }
}
}
1
  • 3
    Here you can get information about how to set up your IDE, if you're using one. Commented Oct 12, 2015 at 6:34

11 Answers 11

5

You need to tell the compiler where to look for the SFML header files. This can be done by passing the -I flag in the compiler invocation:

-I/path/to/SFML/headers
Sign up to request clarification or add additional context in comments.

Comments

2

If you're on Linux then this one liner is the way to go:

sudo apt-get install libsfml-dev

Found it in the docs here: https://www.sfml-dev.org/tutorials/2.1/start-linux.php

Comments

2

In case you have been installing SFML with brew (on Mac) you might be needed to link the include and lib sfml directories in the compilation process. You can do that by first find where SFML was installed using,

brew info sfml

which will give you something similar to this

==> sfml: stable 2.6.1 (bottled), HEAD
Multi-media library with bindings for multiple languages
https://www.sfml-dev.org/
/opt/homebrew/Cellar/sfml/2.6.1 (812 files, 12.7MB) *
  Poured from bottle using the formulae.brew.sh API on 2023-12-05 at 13:54:21
From: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/s/sfml.rb
License: Zlib
==> Dependencies
Build: cmake ✘, doxygen ✘
Required: flac ✔, freetype ✔, libogg ✔, libvorbis ✔
==> Options
--HEAD
    Install HEAD version
==> Analytics
install: 782 (30 days), 2,444 (90 days), 5,295 (365 days)
install-on-request: 740 (30 days), 2,311 (90 days), 4,994 (365 days)
build-error: 0 (30 days)

where you can copy the library path /opt/homebrew/Cellar/sfml/2.6.1.

Next, when compiling your main.cpp file, run the following

g++ -I/opt/homebrew/Cellar/sfml/2.6.1/include -L/opt/homebrew/Cellar/sfml/2.6.1/lib -lsfml-graphics -lsfml-window -lsfml-network main.cpp -o prog
  • -I is for linking the library include directory.
  • -L is for linking the library lib directory.
  • -l is for linking the specific files needed (depends on your specific code), for the sfml website example, the graphics, network and window files will do.

Comments

0

If you happen to be using the windows visual studio command line compiler, the include syntax is:

/I"path\to\SFML\headers"

Comments

0

I guess you did a mistake with you're additional includes and/or libraries. Check this again - and if problem still not solved -then make sure - if you're not using SFML static - if the SFML DLL files are in the right directory

I personally found out, that it is a good idea to place the whole SFMl folder into your C drive.

EDIT A common mistake with SFML and the Linker is writing graphic-d.lib instead of graphics-d.lib (in case of debug mode)

Comments

0

I'm pretty new to this, but if you followed the tutorial, then you probably set the path for the .hpp files as just /include, but the .hpp files are really in /include/SFML

#include <include/SFML/Graphics.hpp>

Comments

0

If you are using Visual Studio, be aware of the following:

  • Make sure that you are applying the configurations for the correct platform (Win32/Win64).

  • Make sure that you are configuring the correct mode (debug/release/all configuration)

  • When you are compiling the code, select the appropriate platform (x86/x64) and configuration (debug/release) from the upper toolbar near the Run button. If the toolbar is hidden, go to View -> Toolbars -> Standard.

  • When configuring the "Input" for the linker, make sure to add -d for the debug mode.

Comments

-1

This may not be correct, but assuming you're coming from the same source as me, when you're linking the SFML include files to your compiler, make sure to separate out the -I command from the file path (-I C:\SFML\include, not -IC:\SFML\include). I was getting the same error, and that is how I finally fixed it.

1 Comment

I don't think that was the problem, in my experience it does not matter if the -I is separated from the path or not.
-1

In my case, the include paths were all correct, but I had neglected to specify the sub-directory of SFML; I had put #include <SFML/Vector2.hpp> instead of #include <SFML/System/Vector2.hpp>.

Comments

-1

that happend to me

you gotta type .\main in terminal do not press Run and Debug

enter image description here

1 Comment

Do not link an image, provide more details on how your answer can solve the problem
-4

delete the spaces from * < SFML/Graphics.hpp > and * < SFML/Window.hpp >

delete the spaces from * < SFML/Graphics.hpp > and * < SFML/Window.hpp >

2 Comments

Sorry, we can't accept images of code, data or errors. Post those as text, so that others can actually copy and use your proposed solution without having to re-type everything, and your answer can be properly indexed or read by screen readers.
The preprocessor ignores spaces here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.