-1

I have a file structure like this:

main.cpp         --> #include <headers/f1/v.h>
headers/f1/v.h   --> #include <headers/f1/i.h>
headers/f1/i.h

headers is a directory of external library. Compiled with 'g++ main.cpp' and got file not found error:

In file included from main.cpp:11:
./headers/f1/v.h:32:10: fatal error: 'headers/f1/i.h' file not found
#include <headers/f1/i.h>

Very new to c++. Really can't figure it out. What has been wrong here? Thanks!

Lightness Races in Orbit
  • 378,754
  • 76
  • 643
  • 1,055
user2683470
  • 189
  • 1
  • 3
  • 15
  • 5
    Use quotes for your own header files, not angle brackets: `#include "headers/f1/v.h"`. – Code-Apprentice Mar 13 '18 at 19:40
  • 1
    " have a file structure like this:" I really doubt you do, as if you did all your source code would be in the root directory, which you almost certainly don't have write access to. –  Mar 13 '18 at 19:42
  • 2
    @NeilButterworth I think that the OP is starting from the project's directory, not the literal root directory. – Code-Apprentice Mar 13 '18 at 19:42
  • @Code-Apprentice Thanks! Actually the entire /f1 folder comes from a library, that's why <> is used here. Also the main problem is that somehow v.h cannot find i.h and I don't suppose I should modified the library files. Any idea? – user2683470 Mar 13 '18 at 20:07
  • 1
    See https://stackoverflow.com/questions/6141147/how-do-i-include-a-path-to-libraries-in-g – Code-Apprentice Mar 13 '18 at 20:08
  • @user2683470: You should really stop calling it `/f1`, `/headers` etc like that. A leading slash is understood to mean "the root of the filesystem" and rules out a relative path. You probably meant `f1`, `headers` etc. (Notice that the compiler did it this way too, in its error message.) That way you don't confuse people! Cheers! – Lightness Races in Orbit Mar 13 '18 at 20:25
  • @LightnessRacesinOrbit sorry about that! – user2683470 Mar 13 '18 at 20:27
  • @user2683470: No apology necessary! – Lightness Races in Orbit Mar 13 '18 at 20:27

1 Answers1

1

When including your own headers, in the same build tree, you should use quotes not angle brackets:

#include "headers/f1/v.h"

If you do get into the situation that you need <> for local files, for whatever reason, you could add the directory to your compiler's include path:

g++ main.cpp -I .

where . is the POSIX convention for "this directory".


Further reading:

Lightness Races in Orbit
  • 378,754
  • 76
  • 643
  • 1,055