C ++文件,包括C头文件 [英] C++ file including C header file
问题描述
我需要包括C头文件在我的C ++项目,但G ++抛出错误不在此范围内声明。
我读,我需要使用externC的关键字来修复它,但它似乎并没有为我工作。
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中:
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
includedFile.h
#include <stdint.h>
enum TypeOfEnum {
ONE,
TWO,
THREE,
FOUR = INT32_MAX,
};
抛出的错误是:
$> 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,
我看到<一个href=\"http://stackoverflow.com/questions/3233054/error-int32-max-was-not-declared-in-this-scope\">this帖子,我可能需要的#define __STDC_LIMIT_MACROS
没有任何成功。
I saw on this post that I may need #define __STDC_LIMIT_MACROS
without any success.
欢迎任何帮助!
推荐答案
&LT; cstdint&GT;
是一个C ++ 11功能。通 -std = C ++ 11
到你的编译器。
<cstdint>
is a C++11 feature. Pass -std=c++11
to your compiler.
这篇关于C ++文件,包括C头文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!