In 100% standard C++, you just plain cannot include standard headers in an extern "C"
block. You would need to modify your include.h
header to be C++-friendly, by first including its required headers outside of extern "C"
, and declaring its own names inside an extern "C"
block.
17.6.2.2 Headers [using.headers]
[...]
3 A translation unit shall include a header only outside of any external declaration or definition, and shall include the header lexically before the first reference in that translation unit to any of the entities declared in that header.
Doing
extern "C" {
#include <complex.h>
}
is invalid, because the header is then included inside of a declaration. This applies even if it's another header that only indirectly includes <complex.h>
.
What may work on common implementations, as a workaround if modifying include.h
is impractical, is to first manually include all the headers that include.h
would include itself. Assuming those headers use the appropriate guards to make a second inclusion a no-op, the fact that include.h
includes them will then not cause any errors.