分析:
这个原因是由于包含头文件有误导致的,我在某个C头文件中包含了C++头文件,报错
解决:
1、C文件函数被包含C++文件方法如下:
#ifdef __cplusplus //bsp_GPIO.h .c 被 cpp文件引用,需要如此添加 extern "C" { #endif //----------本文件需要引出的函数----------// int GPIO_OutEnable(int fd, unsigned int dwEnBits); int GPIO_OutDisable(int fd, unsigned int dwDisBits); int GPIO_OpenDrainEnable(int fd, unsigned int dwODBits); int GPIO_OutSet(int fd, unsigned int dwSetBits); int GPIO_OutClear(int fd, unsigned int dwClearBits); int GPIO_PinState(int fd, unsigned int* pPinState); int GPIO_IrqEnable(int fd, unsigned int dwEnBits); #ifdef __cplusplus } #endif
2、C文件被C++文件引用
在CPP文件中: #ifdef __cplusplus extern "C"{ #endif #include "cJSON.h" #ifdef __cplusplus } #endif
注:C文件不可以引用C++文件,在现实当中,只能够在C++里面引用c文件,不可以在C中引用CPP文件,除非你的CPP文件里完全是使用C写的代码,但可以引用其中函数。子集要用超集,这从逻辑上是不成立的.
C中调用C++函数:https://blog.csdn.net/nizqsut/article/details/52148973