Reputation: 97
I am getting this error when running my code:
fatal error: 'SFML/Graphics.hpp' file not found
#include \<SFML/Graphics.hpp\>
I am using a Mac along with VS Code (would like to use VS but none is supported by Mac it seems).
#include <iostream>
#include <memory>
#include <fstream>
#include <SFML/Graphics.hpp>
#include "imgui/imgui.h"
#include "imgui/imgui-SFML.h"
int main(int argc, char* argv[]) {
sf::RenderWindow window(sf::VideoMode(1280, 720), "SFML Works!");
window.setFramerateLimit(60);
}
Build Output:
Starting build...
/usr/bin/clang++ -std=c++17 -I/opt/homebrew/opt/sfml/include -L/opt/homebrew/opt/sfml/lib /Users/me/Downloads/GP/comp4300-master/assignment1/main.cpp -lsfml-graphics -lsfml-window -lsfml-system -fcolor-diagnostics -fansi-escape-codes -g -o /Users/me/Downloads/GP/comp4300-master/assignment1/main
ld: warning: dylib (/opt/homebrew/opt/sfml/lib/libsfml-system.dylib) was built for newer macOS version (14.0) than being linked (13.3)
ld: warning: dylib (/opt/homebrew/opt/sfml/lib/libsfml-window.dylib) was built for newer macOS version (14.0) than being linked (13.3)
ld: warning: dylib (/opt/homebrew/opt/sfml/lib/libsfml-graphics.dylib) was built for newer macOS version (14.0) than being linked (13.3)
Build finished with warning(s).
* Terminal will be reused by tasks, press any key to close it.
SFML Directory: /opt/homebrew/opt/sfml/include/SFML
If I do ls
:
Audio Graphics.hpp System
Audio.hpp Main.hpp System.hpp
Config.hpp Network Window
GpuPreference.hpp Network.hpp Window.hpp
Graphics OpenGL.hpp
So as you can see, the SFML folder is there along with Graphics.hpp
. There are no red squiggles in my code unless I change the header files.
For example, if I did:
#include <SFML/GGGraphics.hpp> // RED SQUIGGLE
#include <SFML/Graphics.hpp> // NO RED SQUIGGLE, BUT COMPILER ERROR
This would net red squiggles in the header code as there's no such thing as GGGraphics.hpp
, so I infer that the Graphics.hpp
is found, but there's some error.
If I used a different file, but it exists:
#include <SFML/Window.hpp> // RED SQUIGGLE
There would be red squiggles in the main function instead because I needed the Graphics.hpp for sf::RenderWindow
. And of course, VS Code would tell me that Window.hpp
does not exist despite it being there. Hopefully, this information is helpful.
Next, have a look at my config files located in .vscode
.
tasks.json
:
{
"version": "2.0.0",
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: clang build active file",
"command": "/usr/bin/clang++",
"args": [
"-std=c++17",
"-I/opt/homebrew/opt/sfml/include",
"-L/opt/homebrew/opt/sfml/lib",
"${workspaceFolder}/main.cpp",
"-lsfml-graphics",
"-lsfml-window",
"-lsfml-system",
"-fcolor-diagnostics",
"-fansi-escape-codes",
"-g",
"-o",
"${fileDirname}/${fileBasenameNoExtension}"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": ["$gcc"],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "Generated task by Debugger."
}
]
}
c_cpp_properties.json
:
{
"configurations": [
{
"name": "Mac",
"includePath": [
"${workspaceFolder}/**",
"/opt/homebrew/opt/sfml/include"
],
"defines": [],
"macFrameworkPath": [],
"compilerPath": "/usr/bin/clang",
"cStandard": "c17",
"cppStandard": "c++17",
"intelliSenseMode": "macos-clang-arm64"
}
],
"version": 4
}
What have I looked at?
This helped me with tasks.json
The most recent post on this topic, but unhelpful
I wish for the SFML window to pop up, and not this error. Something else I tried on my own was moving the entire SFML folder to my project directory, but while it worked in that the file was located, it was very inefficient because I needed to replace angle brackets with double quotes and reconfigure paths, which was very slow for the whole folder.
How can I get rid of the error that SFML/Graphics.hpp
cannot be found?
Upvotes: 1
Views: 71