c++ - 如何解决链接器错误 "cannot find -lgcc_s"

标签 c++ linux linker g++ static-libraries

我有 3 个小文件,用于制作静态库和应用程序:

test.h

#ifndef TEST_H
#define TEST_H

class Test
{
    public:
        Test();
};

extern Test* gpTest;

#endif

test.cpp

#include "test.h"

Test::Test()
{
    gpTest = this;
}   

Test test;

main.cpp

#include "test.h"
#include <iostream>

using namespace std;

Test* gpTest = NULL;

int main()
{
    return 0;
}

构建

g++ -c test.cpp -o test.o
ar cr test.a test.o
g++ -c main.cpp -o main.o
g++ main.o -o app -Wl,--whole-archive -L/home/dumindara/intest/test.a -Wl,-no--whole-archive

错误(链接步骤)

/usr/lib64/gcc/x86_64-suse-linux/4.3/../../../../x86_64-suse-linux/bin/ld: cannot find -lgcc_s
collect2: ld returned 1 exit status

我尝试了所有方法:使用 -static-libgcc 并链接到静态 libstdc++。不能让它工作。这都是由于 --whole-archive 标志。但我离不开它。

最佳答案

你打错了。 -no--whole-archive 应该是--no-whole-archive。修复拼写错误可修复链接器错误。

关于c++ - 如何解决链接器错误 "cannot find -lgcc_s",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3888409/

相关文章:

c++ - 包含 <execution> header 时出现 tbb 链接器错误

c++ - 使用单色 QImage

linux - NetBeans/Maven/Ant 构建脚本错误 - 环境变量 (Linux)

c - STM32f207ZG NUCLEO 板,ld.exe : section . RxDescripSection VMA [2000e000,2000e09f] 与 .bss VMA 部分重叠 [20000118,2001431b]

c - 为什么管道可以使用的进程之间的关系在 Linux API 和 Bash 中不同

linux - 逐行比较两个文件并使用 shell 脚本找到最大和最小的数字

assembly - ld with -Ttext=0x1000 使文件非常大

C++ 测量函数执行时间的非常奇怪的行为——我的头爆炸了

c++ - 使用 .pfx (pkcs12) 文件而不是 .pem 文件建立 SSL 连接的编程方式

c++ - 无法构建 avahi4j : avahi4j_Client. c :18:32: fatal error: avahi-common/error. h: 没有这样的文件或目录