gcc使用c++库



在c语言程序中调用c++库。需要做以下两步工作:

1、定义头文件时,要加上

 

#ifdef __cplusplus extern “C” { #endif

 

头文件内容

 

#ifdef __cplusplus } #endif

 

这个是表示在c++编译器编译时,生成的函数名使用c语言格式修饰符。

 

2、在用gcc进行链接时,要加上 -lstdc++ 库。且要放在最后。因为gcc是按从右到左的顺序查找依赖库的。

如果没有这一步,会在链接时提示错误:

/usr/bin/ld: /usr/local/lib/libtranscodeipc.a(CCmdLine.o): undefined reference to symbol ‘_Znam@@GLIBCXX_3.4′ /usr/lib/x86_64-linux-gnu/libstdc++.so.6: error adding symbols: DSO missing from command line

 

参考:

http://xinxin8.blog.51cto.com/4141857/820388


Next article

Comment 评论



Share 分享

New Users 最新加入

  • hokurikustr

  • refrain

New comments 最新评论

test123: aasdas Details Apr 13 16:39
admin: Thanks! Details Apr 09 11:46
admin: Google map api Details Apr 09 11:46
lqj12: cooooooooool Details Apr 08 21:34
Yunhan Huang: 这个功能是如何实现的? Details Apr 08 13:23