【问题标题】:Link C++ with statically , libraries not found静态链接 C++,找不到库
【发布时间】:2018-11-20 08:44:32
【问题描述】:

我想将 g++ 二进制文件与 -static 标志链接,但出现此错误 我正在使用 Fedora 29

错误

/usr/bin/ld: cannot find -lstdc++
/usr/bin/ld: cannot find -lm
/usr/bin/ld: cannot find -lc
collect2: error: ld returned 1 exit status

代码

#include <iostream>

int main(){
    std::cout << "Hello" << std::endl;


    return 0;
}

G++线

g++ static.cc -o static -static

【问题讨论】:

  • 我认为在您的系统上库 stdc++ m 和 c 只是动态的
  • 您使用的是什么操作系统?不过,我猜你正在使用 Linux。
  • 如何使它们成为静态的? @ThomasSablik
  • 尝试安装或重新安装 libstdc++-static。在 Centos 上是 yum install libstdc++-static
  • 我不知道我的静态库是从哪里来的,是我安装的还是默认安装的。搜索互联网后,我认为您的构建工具已损坏。也许你需要重新安装你的构建环境。

标签: c++ g++ static-linking


【解决方案1】:

感谢 Thomas,我在执行的 cmets 中找到了解决方案

yum install glibc-static
yum install libstdc++-static

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-10
    • 2023-03-29
    • 2020-12-16
    相关资源
    最近更新 更多