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 another extern "C"
block. Remove the outer blocks.
Two, Boolean
is not a keyword in c++. bool
is. Try adding typedef bool Boolean;
before your header inclusion.
Boolean
is not a standard type for either C
or C++
.
You'll need to find the header where Boolean
is declared and include it before including your file.
You need to provide a definition of the Boolean
type, that the C++ compiler can understand.
The extern "C"
stuff just affects how symbol names are mangled, it doesn't magically make the C++ compiler understand C-specific types.
Not that Boolean
is valid C, anyway. There's probably another header missing from your includes.
You don't need and should not use extern "C"
around the #include
statement. The header already does this right. configstore.h
needs to include the definition of Boolean
. As others have mentioned, you could add the definition of Boolean
to the source file (or include the definition) before including configstore.h
, but this is a bad idea as it creates include order dependencies between unrelated modules.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.