当前位置: 首页 > news >正文

【Linux】Linux64位环境下编译32位报错skipping incompatible的解决办法

本文首发于 ❄️慕雪的寒舍

问题

如题,当我尝试在wsl2的ubuntu中使用-m32选项编译32位程序的时候,出现了下面的两种报错

❯ g++ -m32 test.cpp -o test1 && ./test1
In file included from test.cpp:1:
/usr/include/stdio.h:27:10: fatal error: bits/libc-header-start.h: No such file or directory27 | #include <bits/libc-header-start.h>|          ^~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
❯ g++ -m32 test.cpp -o test1 && ./test1
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/11/libstdc++.so when searching for -lstdc++
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/11/libstdc++.a when searching for -lstdc++
/usr/bin/ld: cannot find -lstdc++: No such file or directory
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/11/libstdc++.so when searching for -lstdc++
collect2: error: ld returned 1 exit status

解决

原因是当前缺少32位的开发库,需要安装

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

安装后重试,编译成功。

❯ g++ -m32  test.cpp -o test1 && ./test1
4

代码很简单,是一个打印指针大小的代码,在32位下指针大小是4,64位下指针大小是8;

#include <stdio.h>int main()
{void * ptr= nullptr;printf("%d\n",sizeof(ptr));return 0;
}

更多说明

在linux下可以使用下面的命令查看你的系统位数。

❯ getconf LONG_BIT
64

参考文章:assembly - /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++ - Stack Overflow

http://www.lryc.cn/news/333730.html

相关文章:

  • vue指令v-model
  • CentOS安装MySQL数据库
  • 从B2B转向B2B2C模式:工业品牌史丹利百得的转型历程
  • Redis群集模式和rsync远程同步
  • JAVA—抽象—定义抽象类Converter及其子类WeightConverter
  • 面对复杂多变的网络攻击,企业应如何守护网络安全
  • 计算机网络练习-计算机网络概述与性能指标
  • vite vue3 ts import.meta在vscode中报错
  • Java synchronized(详细)
  • 算法设计与分析实验报告python实现(排序算法、三壶谜题、交替放置的碟子、带锁的门)
  • 实训问题总结——ajax用get可以成功调用controller方法,用POST就出404错误
  • 1、认识MySQL存储引擎吗?
  • 微信小程序媒体查询
  • 前端(动态雪景背景+动态蝴蝶)
  • 软考-系统集成项目管理中级-新一代信息技术
  • 【卷积神经网络进展】
  • yarn的安装和使用
  • Golang | Leetcode Golang题解之第10题正则表达式匹配
  • 【Leetcode】top 100 图论
  • 【沈阳航空航天大学】 <C++ 类与对象计分作业>
  • Vue3 自定义指令Custom Directives
  • 蓝桥杯 【日期统计】【01串的熵】
  • CSP201409T5拼图
  • mongoDB 优化(2)索引
  • 【2024系统架构设计】案例分析- 5 Web应用
  • 布隆过滤器详解及java实现
  • CloudCompare 点云工具
  • Linux 著名的sudo、su是什么?怎么用?
  • C语言分支语句
  • android 资源文件混淆