C和C++混编译后互相调用函数提示undefined reference to,编译提示成功,可发现调用C++函数时提示
^
[ 98%] Building CXX object CMakeFiles/tapp.dir/zmkzlibdata/udpbrd.cpp.o
[100%] Linking CXX executable tapp
CMakeFiles/tapp.dir/system/Main.c.o: In function `main':
/home/vmuser/nwjzq/sc/zmkz/system/Main.c:492: undefined reference to `udpskt_brdcast'
collect2: error: ld returned 1 exit status
C是采用gcc编译,C++采用g++编译,会导致编译后代码标识名称不一致,调用时候会出错需要做兼容处理,对C++的.h文件里添加针对C语言的声明得以解决
#ifdef __cplusplus
extern "C"{
#endif
int udpskt_brdcast(u_int8_t *buf, u_int32_t len);
#ifdef __cplusplus
}
#endif
#endif
编译成功
[ 96%] Building CXX object CMakeFiles/tapp.dir/zmkzlibdata/mbtcp_slaver.cpp.o
[ 98%] Building CXX object CMakeFiles/tapp.dir/zmkzlibdata/udpbrd.cpp.o
[100%] Linking CXX executable tapp
[100%] Built target tapp
原文链接: https://www.cnblogs.com/azan777/p/15800943.html
欢迎关注
微信关注下方公众号,第一时间获取干货硬货;公众号内回复【pdf】免费获取数百本计算机经典书籍
原创文章受到原创版权保护。转载请注明出处:https://www.ccppcoding.com/archives/185420
非原创文章文中已经注明原地址,如有侵权,联系删除
关注公众号【高性能架构探索】,第一时间获取最新文章
转载文章受原作者版权保护。转载请注明原作者出处!