终于在WSL2下用上了32位的gcc

第一步,去微软官网看doc如何启用WSL2
第二步,安装Ubuntu18,如果上一步成功了,你现在安装的Ubuntu18应该就是WSL2而不是WSL1,用powershell的wsl -l -v去检查,如果还是WSL1,就用wsl --set-version Ubuntu-18.04 2
第三步,用我的bash文本

#需要安装qemu-user-static软件包,添加i386 binfmt,启用i386体系结构
    sudo apt install qemu-user-static
    sudo update-binfmts --install i386 /usr/bin/qemu-i386-static --magic '\x7fELF\x01\x01\x01\x03\x00\x00\x00\x00\x00\x00\x00\x00\x03\x00\x03\x00\x01\x00\x00\x00' --mask '\xff\xff\xff\xff\xff\xff\xff\xfc\xff\xff\xff\xff\xff\xff\xff\xff\xf8\xff\xff\xff\xff\xff\xff\xff'
 
#启用i386架构和软件包
    sudo dpkg --add-architecture i386
    sudo apt install cpp-7:i386
    sudo apt install cpp:i386
    sudo apt install gcc:i386
 
#每次重新启动WSL并需要i386支持时,都需要重新激活此功能:
    sudo service binfmt-support start

#使用apt看自己的gcc:i386是否已安装
    sudo apt show gcc:i386

#使用gcc -m32 hello.c来编译32位的东西
 
#禁用i386支持
#    sudo service binfmt-support stop


第四步,用gcc的-m32选项进行编译,你就能看到自己的sizeof(long)是4了

猜你喜欢

转载自blog.csdn.net/u013474815/article/details/109055509
今日推荐