[GCC][Windows] header file inclusion on windows
David Brown
david.brown@hesbynett.no
Sat Jan 28 14:04:08 GMT 2023
On 28/01/2023 04:57, Mena Makary via Gcc-help wrote:
> Hello GCC Help Team,
>
> Could you please support on the following C code example:
>
> #include "header.h" /* Proper file name like on windows file system, No
> error is expected */
> #include "Header.h" /* Same file but H letter is camelcased by mistake,
> Error is expected */
> #include "header.h " /* Same file but a space is added before end of file
> inclusion by mistake, Error is expected */
>
> The problem here is that the above two issues are not detected by GCC
> on windows, while could be detected on Linux.
> Is there any compiler option/flag enables GCC to detect such issues on
> Windows?
>
I think this is inevitable for Windows. The compiler will ask for the
header by trying to open a file called "header.h", "Header.h" or
"header.h ", and the OS will give them file, because on Windows these
all refer to the same file due to case-insensitive and space-striping
names. So the compiler has no way to report this as an issue - because
on Windows, it is /not/ an error. It is the expected behaviour of the
system.
In theory, I suppose, the compiler could ask for a details of the file
or a directory listing, and compare the stored name (as file names are
case-preserving in Windows) to the name requested by the pre-processor.
But that would be a lot of extra work for no purpose for a compiler, and
would break code that currently compiles fine on Windows.
I don't know what you are aiming to do here. But one possibility is to
use one of the "-M" options for gcc to create a "make" dependency file
that lists the headers included by the file. A small Python script
could parse that, read the true filename for the file on the Windows
filesystem, and compare them.
Another possibility is to run the compilation using a Cygwin
environment, rather than more common mingw gcc builds. Under Cygwin,
filenames are case sensitive.
More information about the Gcc-help
mailing list