我遇到的DSO missing from command line

本文介绍了解决C语言项目调用C++静态链接库时出现的符号未定义错误的方法。通过更改编译器从gcc为g++成功解决了问题,并分享了一次在大型项目中遇到类似错误及解决方案。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

首先,使用C++代码编译了一个静态链接库libmy.a. 然后在另外一个C语言的项目中去调用此静态库,结果出现如下错误:

/usr/bin/ld: libmy.a(message_mm.o): undefined reference to symbol ‘_ZTVN10__cxxabiv117__class_type_infoE@@CXXABI_1.3’
//usr/lib/x86_64-linux-gnu/libstdc++.so.6: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
makefile:36: recipe for target ‘main’ failed
make: *** [main] Error 1

在C语言的项目中,makefile使用的是gcc来编译和链接,因此怀疑是C与C++链接时的兼容问题,于是在C项目中改用g++,果然没有问题了。


2019.2.22 补充
今天编代码又遇到此错误:

/usr/bin/ld: …/…/base/framework/.libs/libossiecf.a(libossiecf_la-prop_helpers.o): undefined reference to symbol ‘_ZlSRN5CORBA3AnyEPNS_9DoubleSeqE’
//usr/local/lib/libomniDynamic4.so.2: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
Makefile:601: recipe for target ‘nodeBooter’ failed
make[2]: *** [nodeBooter] Error 1
make[2]: 离开目录“/home/xxx/source/redhawk-src-2.0.8/redhawk/src/control/framework”
Makefile:482: recipe for target ‘all-recursive’ failed
make[1]: *** [all-recursive] Error 1
make[1]: 离开目录“/home/xxx/source/redhawk-src-2.0.8/redhawk/src/control”
Makefile:600: recipe for target ‘all-recursive’ failed
make: *** [all-recursive] Error 1

这样的错误原因就是libomniDynamic4.so.2未找到。解决方法很简单,在编译选项中加-lomniDynamic4

评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值