C调用C++函数

来源:互联网 发布:sd卡数据恢复软件 编辑:程序博客网 时间:2024/06/05 00:18

#ifdef _cplusplus

extern "C"

{

#endif


int myfunc();


#ifdef __cplusplus
}
#endif


在 cpp文件中:

需要:

extern "C" int myfunc(){}


接下来,将cpp文件编译成.o文件,如:g++ -c detect.cpp detect.o

最后将多个.o文件编译成一个.a文件,如ar cr detect.o lan.o  libtest.a

在makefile文件中添加对.a的链接,如XLIB  -ltest







原创粉丝点击