Including your own C header files from C++

To include your own C header files, you must wrap the #include directive in an extern "C" statement. You can do this in the following ways:

Example 11. Directive before include file

// C++ code
extern "C" {
#include "my-header1.h"
#include "my-header2.h"
int main()
    // ...
    return 0;

Example 12. Directive in file header

/* C header file */
#ifdef __cplusplus    /* Insert start of extern C construct */
extern "C" {
/* Body of header file */
#ifdef __cplusplus  /* Insert end of extern C construct. */
}                   /* The C header file can now be      */
#endif              /* included in either C or C++ code. */

Copyright © 2010-2012 ARM. All rights reserved.ARM DUI 0471G