SFML community forums

Help => Graphics => Topic started by: PolyyloP on April 07, 2020, 08:05:51 am

Title: Error with include in header file
Post by: PolyyloP on April 07, 2020, 08:05:51 am
Hello,

I know different versions of this question have been asked all over the internet, but I can't find anything explaining the issue I am having. I am running SFML on Ubuntu 18.04. When I compile an SFML '.cpp' file to an object file, everything works fine, but when I move the forward declarations of the file into a header file, and recompile, I get the error "fatal error: SFML\Graphics.hpp: No such file or directory".

Why can't I use SFML in header files. The code is identical and should work the same as when I have it all in a .cpp file.

Thanks,
-PolyyloP
Title: Re: Error with include in header file
Post by: eXpl0it3r on April 07, 2020, 10:27:51 am
You shouldn't use backslashes in your path, especially on Linux where all paths use forward slashes.

Other than that, can you provide your build command? And your minimal code example?
Title: Re: Error with include in header file
Post by: PolyyloP on April 09, 2020, 08:01:10 pm
Ah, yes! Changing the direction of the slash fixed the issue. That is strange that it threw an error in the header file but not in a .cpp file. In any case, the code is for a slider that I downloaded from GitHub (link below). Not sure why the author used an incorrect slash. Does it vary by OS?

My build commands:
g++ -c SliderSFML.cpp
g++ -c main.cpp
g++ main.o SliderSFML.o -o main

https://github.com/N4G1/Slider-SFML

Thanks!
-Poly
Title: Re: Error with include in header file
Post by: Hapax on April 09, 2020, 10:46:42 pm
Not sure why the author used an incorrect slash. Does it vary by OS?
Sort of, yes.
Windows, for example, allows - and positively encourages - backslashes. However, it happily (and more safely) accepts slashes. Since all OSs can use slashes, it's almost definitely best to avoid backslashes as it makes the code more universal. (there are no real downsides)
Title: Re: Error with include in header file
Post by: PolyyloP on April 11, 2020, 02:30:01 am
Thanks!