c++代码包含c代码出现警报:Undefined reference to crc_16(unsigned char const*, unsigned long, unsigned short)
crc_16(unsigned char const*, unsigned long, unsigned short)是C语言编写的函数。
解决办法:
extern "C" { #include "crc_16.h" }
告诉C++编译器,这段代码用C编译器进行编译。
原因:
编译后的函数名在C和C++之间是不同的。C编译器后的crc_16(…)名称将只是_crc_16。在c++编译器之后,它的名字应该类似于crc_16__Fcii。extern "C"只是告诉编译器这些名称应该是C格式的