如何将linuxarm交叉编译到x86
我使用的是 m1 pro macbook pro。 到目前为止,我使用的是intel macbook。
我的程序是用c/c++编写的,目标是ubuntu x86_64。
我尝试运行 ubuntu x86 docker (qemu),它非常慢 - 以至于无法使用。 我使用并行安装了 linux ubuntu (arm),并且想针对 x86 目标而不是 arm 进行编译。
我该怎么做?
I'm using an m1 pro macbook pro.
Up until now, I used intel macbook.
My program is written in c/c++ and the target is ubuntu x86_64.
I tried running ubuntu x86 docker (qemu) and it's super slow - to the point it's unusable.
I have linux ubuntu (arm) installed using parallels and would like to compile for x86 target instead of arm.
How do I do it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在 Ubuntu 上,我建议使用 apt install gcc-x86-64-linux-gnu g++-x86-64-linux-gnu,然后使用 x86-64- 调用已安装的编译器linux-gnu 前缀(对于 gcc,
x86-64-linux-gnu-gcc
)来创建 x86_64 二进制文件。请注意,如果您的目标为 x86_64,您将无法运行您本地构建的程序,但您应该能够打包为在 x86_64 计算机上执行而创建的二进制文件。
On Ubuntu, I would suggest an
apt install gcc-x86-64-linux-gnu g++-x86-64-linux-gnu
, and then invoking the installed compiler with thex86-64-linux-gnu
prefix (for gcc,x86-64-linux-gnu-gcc
) to create x86_64 binaries.Do note that if you target x86_64 you won't be able to run the programs you build natively, but you should be able to package the binaries created for execution on an x86_64 machine.
在您的 Mac 上安装 docker-desktop 并使用以下命令运行此 docker 容器:
不要忘记为代码目录创建卷。
在浏览器中访问:http://localhost:6080/vnc.html 访问 xubuntu 桌面
Dockerhub 上的图片
Install docker-desktop on your mac and run this docker container with the command:
Don't forget to create volume to the code directory.
In your browser go to: http://localhost:6080/vnc.html to access the xubuntu desktop
Image on Dockerhub