[32.3] How can I include a non-system C header file in my C++ code?
If you are including a C header file that isn't provided by the system, you may
need to wrap the #include line in an extern "C" { /*...*/ }
construct. This tells the C++ compiler that the functions declared in the
header file are C functions.
// This is C++ code
extern "C" {
// Get declaration for f(int i, char c, float x)
#include "my-C-code.h"
}
int main()
{
f(7, 'x', 3.14); // Note: nothing unusual in the call
...
}
Note: Somewhat different guidelines apply for
C headers provided by the
system (such as <cstdio>) and for
C
headers that you can change.