加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Linux > 正文

linux – 如何解决’collect2:ld返回1退出状态’?

发布时间:2020-12-14 02:19:53 所属栏目:Linux 来源:网络整理
导读:当我在 linux中构建我的源代码时,我得到了一个错误 qstring.cpp:(.text+0x2c01): undefined reference to `terminate(void)'collect2: ld returned 1 exit status 如何解决这个问题呢? 解决方法 terminate在C标准库中定义,因此请确保将其链接到.假设您正在
当我在 linux中构建我的源代码时,我得到了一个错误
qstring.cpp:(.text+0x2c01): undefined reference to `terminate(void)'
collect2: ld returned 1 exit status

如何解决这个问题呢?

解决方法

terminate在C标准库中定义,因此请确保将其链接到.假设您正在使用gcc进行编译,您应该使用g可执行文件来编译源代码,而不是gcc可执行文件:
g++ source.cc -o output

当以g执行时,链接器会自动链接到C标准库(libstdc)中.如果您改为将gcc作为普通gcc执行,或者直接调用链接器ld,那么您需要自己添加-lstdc以链接库,例如:

gcc source.cc -o output -lstdc++  # Compile directly from source
ld source1.o source2.o -o output -lstdc++  # Link together object files

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读