/usr/bin/ld: 在搜索 -lstdc++ 时跳过不兼容的 /usr/lib/gcc/x86_64-linux-gnu/9/libstdc++.a /usr/bin/ld: 找不到 -lstdc++
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/9/libstdc++.a when searching for -lstdc++ /usr/bin/ld: cannot find -lstdc++
为什么我会收到这个错误?
g++ -m32 func.o test.o -o prgram
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/9/libstdc++.so when searching for -lstdc++
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/9/libstdc++.a when searching for -lstdc++
/usr/bin/ld: cannot find -lstdc++
collect2: error: ld returned 1 exit status
我的代码如下:
#include<stdio.h>
2
3
4 extern "C" int calcsum(int a, int b, int c);
5
6 int main(int argc,char* argv[])
7 {
8 int a = 10;
9 int b = 20;
10 int c = 30;
11 int sum = calcsum(a,b,c);
12
13 printf("a: %d", a);
14 printf("b: %d", b);
15 printf("c: %d", c);
16 printf("sum: %d", sum);
17 return 0;
18 }
19
1 section .text
2 global _start
3 _start:
4 global _calcsum
5 _calcsum:
6
7 push ebp
8 mov ebp, esp
9
10 mov eax, [ebp+8]
11 mov ecx, [ebp+12]
12 mov edx, [ebp+16]
13
14 add eax, ecx
15 add eax, edx
16
17 pop ebp
18 ret
您正在 64 位系统上构建 32 位二进制文件(因为您使用了 -m32
标志),但尚未安装 32 位版本的开发库。
如果您使用的是 Ubuntu,请尝试:
sudo apt install gcc-multilib g++-multilib libc6-dev-i386
至于你的汇编文件,它不能按原样工作。 start
将由cpp 文件定义,因此将其从asm 文件中删除。接下来,删除 _calcsum
中的下划线。构建 ELF 二进制文件时,函数名称不以下划线开头:
section .text
global calcsum
calcsum:
push ebp
mov ebp, esp
mov eax, [ebp+8]
mov ecx, [ebp+12]
mov edx, [ebp+16]
add eax, ecx
add eax, edx
pop ebp
ret
将其构建为 32 位 ELF 目标文件:
nasm -felf32 func.s -o func.o
为什么我会收到这个错误?
g++ -m32 func.o test.o -o prgram
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/9/libstdc++.so when searching for -lstdc++
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/9/libstdc++.a when searching for -lstdc++
/usr/bin/ld: cannot find -lstdc++
collect2: error: ld returned 1 exit status
我的代码如下:
#include<stdio.h>
2
3
4 extern "C" int calcsum(int a, int b, int c);
5
6 int main(int argc,char* argv[])
7 {
8 int a = 10;
9 int b = 20;
10 int c = 30;
11 int sum = calcsum(a,b,c);
12
13 printf("a: %d", a);
14 printf("b: %d", b);
15 printf("c: %d", c);
16 printf("sum: %d", sum);
17 return 0;
18 }
19
1 section .text
2 global _start
3 _start:
4 global _calcsum
5 _calcsum:
6
7 push ebp
8 mov ebp, esp
9
10 mov eax, [ebp+8]
11 mov ecx, [ebp+12]
12 mov edx, [ebp+16]
13
14 add eax, ecx
15 add eax, edx
16
17 pop ebp
18 ret
您正在 64 位系统上构建 32 位二进制文件(因为您使用了 -m32
标志),但尚未安装 32 位版本的开发库。
如果您使用的是 Ubuntu,请尝试:
sudo apt install gcc-multilib g++-multilib libc6-dev-i386
至于你的汇编文件,它不能按原样工作。 start
将由cpp 文件定义,因此将其从asm 文件中删除。接下来,删除 _calcsum
中的下划线。构建 ELF 二进制文件时,函数名称不以下划线开头:
section .text
global calcsum
calcsum:
push ebp
mov ebp, esp
mov eax, [ebp+8]
mov ecx, [ebp+12]
mov edx, [ebp+16]
add eax, ecx
add eax, edx
pop ebp
ret
将其构建为 32 位 ELF 目标文件:
nasm -felf32 func.s -o func.o