Reputation: 205
If the current directory contains a file with the same name as a system header, the compiler will first search the current directory even for includes from within system headers.
Is there a way to avoid that?
Simple reproduction case:
Working directory contains an empty limits.h
and main.cpp
with
#include <climits>
#include <iostream>
int main() {
std::cout << INT_MAX << std::endl;
}
Running either g++ main.cpp
or clang main.cpp
causes an error saying that INT_MAX
was not declared. With the limits.h
absent, compilation works and the program works as expected. The <climits>
system header on my system (ArchLinux updated at 21-04-2023) declares only LLONG
limits and includes <limits.h>
for the rest. However that seems to include my empty limits.h
instead of the system one.
I ran into this issue in a more complex project when including <memory>
, which included <limits.h>
6 files deep.
Upvotes: 0
Views: 22