此情况分两种:
- 一、 函数未定义
此时应该在正确的文件中定义该文件。例如:函数void add(uint8_t a, uint8_t b)
在math.h 中声明:uint8_t add(uint8_t a, uint8_t b);
在对应的math.c中定义
uint8_t add(uint8_t a, uint8_t b) {
return a + b;
}
二、C和C++混合编程
此时应是
- C中调用C++中的函数
- C++中调用C文件函数
若是情况1.则应将C++中的函数导出;
即在C++函数前加extern "C" .例如:
extern "C" void TBS_Launch() {
// 等待从机就绪
TBS_Delay(100);
TBS_Test();
TBS_Started();
}
若有函数需要外部声明的,也应当加extern "C" ,例如:
extern "C" {
extern void TBS_ScreenEvent(void * info);
extern void ReceivedOutputControllerDataEvent(void * info);
}
若是情况2则应将C中函数导入;例如:
#ifdef __cplusplus
extern "C" {
#endif
Your code...
#ifdef __cplusplus
}
#endif
函数声明

16万+

被折叠的 条评论
为什么被折叠?



