/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++

查看:58
本文介绍了/usr/bin/ld: 在搜索 -lstdc++ 时跳过不兼容的/usr/lib/gcc/x86_64-linux-gnu/9/libstdc++.a/usr/bin/ld: 找不到 -lstdc++的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么我会收到这个错误?

why am i getting this error?

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 位版本的开发库.

You are building a 32-bit binary on a 64-bit system (because you used the -m32 flag), but have not installed 32-bit versions of the development libraries.

如果您使用的是 Ubuntu,请尝试:

If you're on Ubuntu, try:

sudo apt install gcc-multilib g++-multilib libc6-dev-i386

至于您的程序集文件,它不能按原样工作.start 将由 cpp 文件定义,因此将其从 asm 文件中删除.接下来,从 _calcsum 中删除下划线.构建 ELF 二进制文件时,函数名称不以下划线开头:

As for your assembly file, it can't work as-is. start will be defined by the cpp file, so remove it from the asm file. Next, remove the underscore from _calcsum. When building ELF binaries, function names do not start with an underscore:

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 目标文件:

Build that as a 32-bit ELF object file with:

nasm -felf32 func.s -o func.o

这篇关于/usr/bin/ld: 在搜索 -lstdc++ 时跳过不兼容的/usr/lib/gcc/x86_64-linux-gnu/9/libstdc++.a/usr/bin/ld: 找不到 -lstdc++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆