g++ include path

Hello,
I trying to compile a rather large project initially written and compiled with MSVC++ using g++ in Linux. Within the project I have a local include folder, which I specify in my Makefile as a "CFLAG=-I/path/to/include".

This works well, as long as the header files within the include folder don't use other header files living in the same include folder. When a header file from the include folder includes another header file from this same folder, I get this compile error (../../Include is the local include folder):
../../Include/headers/header_1.h:9:35: fatal error: headers/header_2.h: No such file or directory

If it found header_1.h why doesn't it find header_2.h, given that they are in the same folder?
Any ideas?
Thanks!
I cannot reproduce your error, ┬┐could you provide a minimal example?
This works well, as long as the header files within the include folder don't use other header files living in the same include folder.
Are you including these files with <> or ""?
@ne555: funny thing: I can't reproduce it with a minimal example...that works just fine. The problem seems to lie somewhere else. I will keep trying.

@kbw: I have tried either way...


Anyway, I found out that if I include header_2.h as "header_2.h" without path, it works fine. I don't like that solution, but if it works......

Thanks for the help.
Why would you use hard-coded paths in any of your source-files?

...usually you would pass the "include" folder to g++ via compiler flag:

g++ -c -o test.o -I ../include/ test.cpp

This way you can use either file anywhere and won't get path problems...

-I == capital i
Last edited on
It's not that I want to....the code is not written by me originally. I am just trying to port it from MSVC to gcc, and I'd wanted to avoid changing all those headers.

But it seems there is no way around it ;)
But it seems there is no way around it ;)

Sure there is, you just have to do it right.

If it found header_1.h why doesn't it find header_2.h, given that they are in the same folder?

You're not including header_2.h, you're including headers/header_2.h, which apparently does not exist in any of the include paths.
Mhm...since you're under *nix maybe you could symlink the /header folder into itself ?? All header files should find themself then in a pseudo subfolder?!

e.g. ln -s . include

(replace include with whatever path your headers included)
Topic archived. No new replies allowed.