网站制作专业,做外贸流程详细步骤,网站建设案例精粹 电子书,电子商务网站建设概念本文首发于 ❄️慕雪的寒舍 问题
如题#xff0c;当我尝试在wsl2的ubuntu中使用-m32选项编译32位程序的时候#xff0c;出现了下面的两种报错
❯ g -m32 test.cpp -o test1 ./test1
In file included from test.cpp:1:
/usr/include/stdio.h:27:10: fatal error… 本文首发于 ❄️慕雪的寒舍 问题
如题当我尝试在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位下指针大小是464位下指针大小是8
#include stdio.hint 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