1

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!

Community
  • 1
  • 1
fdeslaur
  • 144
  • 2
  • 8

1 Answers1

0

<cstdint> is a C++11 feature. Pass -std=c++11 to your compiler.

T.C.
  • 133,968
  • 17
  • 288
  • 421