C++ file including C header file

Posted by fdeslaur on Stack Overflow See other posts from Stack Overflow or by fdeslaur
Published on 2014-06-08T03:05:13Z Indexed on 2014/06/08 3:24 UTC
Read the original article Hit count: 101

Filed under:
|
|
|

I need to include a C header file in my C++ project but g++ throws "not declared in this scope" errors. I read that i need to use extern "C" keyword to fix it but it didn't seem to work for me.

Here is a dummy example triggering this error.

main.cpp:

#include <iostream>
extern "C"
{
#include "includedFile.h"
}
int main()
{
    int a = 2;
    int b = 1212;
    std::cout<< "Hello World!\n";

    return 0;
}

includedFile.h

#include <stdint.h>
enum TypeOfEnum {
    ONE,
    TWO,
    THREE,
    FOUR = INT32_MAX,
};

The error thrown is :

$> g++ main.cpp 
In file included from main.cpp:4:0:
includedFile.h:7:9: error: ‘INT32_MAX’ was not declared in this scope
FOUR = INT32_MAX,

I saw on this post that I may need #define __STDC_LIMIT_MACROS without any success.

Any help is welcome!

© Stack Overflow or respective owner

Related posts about c++

Related posts about c