Somehow this is the first time I’ve ever encountered this problem in many years of programming, and I’m not sure what the options are for handling it.
I am in the process of porting an application to Linux, and there is a header file in one of the directories that apparently has the same name as a header file in the standard C library, and when “cstdlib” is included from another file in that directory, it’s trying to include the local file rather than the correct one from the standard library.
In particular, the file is named “endian.h”, which is trying to be included from /usr/include/bits/waitstatus.h. So instead of including /usr/include/bits/endian.h it is trying to include ./endian.h. makes no difference
Is my only option to rename the endian.h in the project to something else, or is there a way that I can force the compiler to look in the same directory as the file that it’s being included from first?
Edit:
Okay it was just a stupid mistake on my part. My Makefile was setting -I. , so it was looking in the current directory first. D’oh.
There is an important difference between:
And
If you want the one in the current directory, use the quotes. If you want the system one, then use the angle brackets. Note that if you have put the current directory in the include path via the “-I” flag, then both might resolve to the one in the current directory, in which case you shouldn’t use “-I” with the current directory.