包括c头文件在c ++文件 [英] including c header in c++ file
问题描述
我试图在cpp文件中包含一个c头文件。
c头文件具有关键字Boolean。
c头像这样:
#ifndef _CONFIGSTORE_H_
#define _CONFIGSTORE_H_
#ifdef __cplusplus
externC
{
# endif
Boolean ConfigStoreIsPassword(char * pName);
#ifdef __cplusplus
}
#endif
#endif // _ CONFIGSTORE_H_
下面是我在cpp文件中包含c头的方法:
externC{
#includeconfigstore.h
}
或
#ifdef __cplusplus
pre>
externC
{
#endif
#includeconfigstore.h
#ifdef __cplusplus
}
#endif
无论哪种方式,我得到以下错误:
../../../../src/Common/framework/configstore .h:52:error:'Boolean'不指定类型
你能否让我知道如何在cpp文件中添加c头
先感谢!
-Vasavi
解决方案在这里。一,你在另一个
externC
块中嵌套一个externC
删除外部块。
两个,
布尔
不是c ++中的关键字。bool
是。请尝试在头包含之前添加typedef bool Boolean;
。I am trying to include a "c" header file in a cpp file. The c header file has the keyword "Boolean".
c header looks something like this:
#ifndef _CONFIGSTORE_H_ #define _CONFIGSTORE_H_ #ifdef __cplusplus extern "C" { #endif Boolean ConfigStoreIsPassword(char *pName); #ifdef __cplusplus } #endif #endif //_CONFIGSTORE_H_
Below is the way i am including the c header in my cpp file:
extern "C"{ #include "configstore.h" }
or
#ifdef __cplusplus extern "C" { #endif #include "configstore.h" #ifdef __cplusplus } #endif
Either way i include, i get the below error: ../../../../src/Common/framework/configstore.h:52: error: 'Boolean' does not name a type
Could you please let me know how i can add the c header in cpp file Thanks in advance!!
-Vasavi
解决方案Two things spring to mind here. One, you are nesting an
extern "C"
block inside anotherextern "C"
block. Remove the outer blocks.Two,
Boolean
is not a keyword in c++.bool
is. Try addingtypedef bool Boolean;
before your header inclusion.这篇关于包括c头文件在c ++文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!