C++ file including C header file [duplicate]

房东的猫 提交于 2019-12-11 08:46:55

问题


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!


回答1:


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



来源:https://stackoverflow.com/questions/24102616/c-file-including-c-header-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!