qt 编译c文件,extern “c”

来源:互联网 发布:基因表达数据 编辑:程序博客网 时间:2024/04/27 10:01

以前使用C++的时候,好像没用到别的C文件,今天编译一个QT程序,需要用到之前的一个C文件,就改了pro文件把C源码添加进去,可是编译半天都报错,就是函数找不到,类似于:

main.cpp:(.text+0xab0): undefined reference to `xxxxx()'

原来,这是C/C++兼容问题,在C的头文件添加extern "C"即可解决,例如:

#ifndef _C_H_#define _C_H_#ifdef __cplusplusextern "C" {#endifextern int add(int, int);#ifdef __cplusplus}#endif#endif /* _C_H_ */ 

神奇的extern "C",终于有了领悟。看这篇文章,解析的更加详细:

http://www.dianyuan.com/article/29513