c++ - 静态链接 C++,找不到库

标签 c++ g++ static-linking

我想用 -static 标志链接一个 g++ 二进制文件,但我得到了这个错误 我正在使用软呢帽 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

最佳答案

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

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

关于c++ - 静态链接 C++,找不到库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53389167/

相关文章:

c++ - ISO 禁止声明没有类型的 "identifier"。

c++ - 系统头文件/usr/include/i386_types.h错误

c - 将 libvips 静态链接到 Windows 中的 Rust 程序

c++ - 在 svm-predict 命令中使用字符串流而不是文件流

c++ - #ifdef/#define Include-Guard 之前的#include 可以吗?

c++ - 从可执行文件中找出编译优化标志

c++ - 从system()调用G++返回错误

c++ - 如何绕过不受支持的 C++11 代码

ios - 链接 Xcode 6/LLVM 6 的选择性库

c++ - 如何使用 Xcode 在 C++ 项目中添加静态库