Undefined Reference error when linking c function in c++
Post Date: 2018-12-04
Please noted that C and C++ are different languages. Their compiler will create different symbol names on object. So C++ linker cannot find the correct symbol which is compiled by C compiler.
If you want to link the C function in C++, you have to define the function with extern "C"
block. Here is the example:
#ifdef __cplusplus
extern "C" {
#endif
void printhex(const unsigned char *buf, size_t n);
#ifdef __cplusplus
}
#endif
References: