I have following folder structure:
project ├── header1.h ├── folder │ └── header2.h └── main.cpp With following sources:
//main.cpp #include "header1.h" #include "folder/header2.h" int main() {} //header1.h #pragma once void function1() {} //folder/header2.h #pragma once #include "header1.h" void function2() {} So 'header2.h' is including 'header1.h' which is not in the same folder.
Compiling this code with cl main.cpp is successful:
Microsoft (R) C/C++ Optimizing Compiler Version 19.00.24215.1 for x86 Copyright (C) Microsoft Corporation. All rights reserved. main.cpp Microsoft (R) Incremental Linker Version 14.00.24215.1 Copyright (C) Microsoft Corporation. All rights reserved. /out:main.exe main.obj
But for gcc main.cpp I get error:
In file included from main.cpp:2:0: folder/header2.h:2:21: fatal error: header1.h: No such file or directory #include "header1.h" ^ compilation terminated.
Which totally makes sense. Seems like Microsoft is using their own rules to resolve includes. Is there a way to disable this behavior for cl (and Visual Studio)? Is there a way to enable cl-like behavior for gcc?
UPD.
I have checked with Clang 4.0.0 clang++ main.cpp on Windows:
In file included from main.cpp:2: ./folder/header2.h:2:10: warning: #include resolved using non-portable Microsoft search rules as: ./header1.h[-Wmicrosoft-include] #include "header1.h" ^ 1 warning generated.
And it even has a specific rule -Wmicrosoft-include for that.