extern "C" for header files not working

In a C++ project including C header inside of an extern "C" block is not recognized in the editor.  The code compiles just fine, but all of the code using the symbols in those header files show as error.  Also the editor will give the option to auto add the header file outside of the extern "C".  This solves the errors in the editor, but then the code will not link because of name mangling.  It seems that CLion does not properly understand extern "C" code blocks.  For example, I have a C++ application that is using ffmpeg and contains the following include section:

// ffmpeg includes
extern "C"
    #include <libavcodec/avcodec.h>
    #include <libavutil/mathematics.h>
    #include <libavutil/pixdesc.h>
    #include <libavformat/avformat.h>
    #include <libswscale/swscale.h>

Since the ffmpeg libraries are all C, you must include them from inside an extern "C" block or you will face linker issues.

Comment actions Permalink

Hi Paul.

It correctly works for me on the simplest example:

extern "C" {
    #include "fun.h"

int main() {
    return 0;

Could you please specify what CLion version do you use and also send us a full example to clion-support at jetbrains.com?

Comment actions Permalink

I found the reason it was not displaying correctly for me.  I had the extern "C" inside of a header file and that inside of the #ifndef of the header file.  Moving the extern "C" block outside of the header's #ifndef block solved the display issue.  I can not give the source that showed the issue, but will try to build a contrived example.


Please sign in to leave a comment.