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

Author Topic: Error with include in header file  (Read 2260 times)

0 Members and 1 Guest are viewing this topic.

PolyyloP

  • Newbie
  • *
  • Posts: 4
    • View Profile
Error with include in header file
« 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

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11033
    • View Profile
    • development blog
    • Email
Re: Error with include in header file
« Reply #1 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?
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

PolyyloP

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: Error with include in header file
« Reply #2 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
« Last Edit: April 09, 2020, 08:03:39 pm by PolyyloP »

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Error with include in header file
« Reply #3 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)
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

PolyyloP

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: Error with include in header file
« Reply #4 on: April 11, 2020, 02:30:01 am »
Thanks!