如何在只有Busybox的QEMU虚拟机中安装GCC和其他开发人员工具?

发布于 2025-02-13 15:38:02 字数 502 浏览 0 评论 0原文

我下载了Linux内核源代码,成功地对其进行了编译,并在QEMU中使用BusyBox运行它。

由于Busybox,我可以使用一些常用的工具,例如vilscpcat等等。

但是,当我尝试编译简单的“ Hello World” C/C ++程序时,我会得到gcc:找不到

此外,我不能make make -c/lib/lib/$(shell uname -r)/build/build/m = $(pwd)模块内部QEMU。

我谷歌搜索了很多,仍然无法弄清楚。

所以我的问题是:如何安装gccmake等的通用开发人员工具,我的自定义Linux内核(而不是标准分布)?

I download Linux kernel source code, successfully compiled it and run it with BusyBox in QEMU.

Because of BusyBox, I can use some frequently-used tools, such as vi,ls,cp,cat, etc.

But when I try to compile a simple "hello world" C/C++ program, I get gcc: not found.

In addition, I can't make a new Linux module by make -C /lib/modules/$(shell uname -r)/build/ M=$(PWD) modules inside QEMU.

I googled a lot, still can't figure it out.

So my question is: how can I install common developer tools like gcc, make, etc. inside my bare-bones QEMU VM that is running my custom Linux kernel (and not a standard distribution)?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

扶醉桌前 2025-02-20 15:38:02

我看到您正在尝试编译某些程序(或模块)在QEMU机器中使用它,但是您在计算机本身中没有安装编译器工具链。您有几个选择:

  1. 可能是最简单的:由于您已经编制了用于外部QEMU(在主机机中)使用的内核,因此您也可以轻松地以这种方式编译其他任何内容。对于模块,只需指向make到构建VM内核的同一内核源目录就足够了。一旦编译,您就可以像BusyBox一样在VM磁盘/图像中复制它们。

  2. 您可以下载并编译自己的GCC 来自源(始终在主机上),然后将其安装在QEMU虚拟机中。这通常是通过安装VM磁盘(QEMU映像或您使用的任何内容)(例如/mnt/my-qemu-disk),然后用> - prefix =/配置GCC来完成。 mnt/my-qemu-disk/usr/local,使用Make Install构建和安装它。此和其他内容在此文档页面

    在计算机内安装了GCC后,您应该能够像平常一样使用它。现在,您可以使用它来编译 gnu make 在VM内部,或者您只需在外面编译外部以同样的方式。

    对于复杂的内容,例如构建内核模块,您可能还需要构建和安装 gnu binutils 在机器中,您要么从内部使用刚刚安装的GCC或从外部进行。


I see that you are trying to compile some program (or module) to use it inside your QEMU machine, but you do not have a compiler toolchain installed in the machine itself. You have a couple of options:

  1. Probably the easiest: since you already compiled the kernel that you are using for QEMU externally (in your host machine), you can easily also compile anything else this way. For modules, just pointing make to the same kernel source directory where you built the VM kernel should suffice. Once compiled you can then copy them inside the VM disk/image like you did for busybox.

  2. You can download and compile your own GCC from source (always on the host), and then install it inside the QEMU virtual machine. This is usually done by mounting the VM disk (QEMU image or whatever you are using) somewhere (e.g. /mnt/my-qemu-disk) and then configuring GCC with --prefix=/mnt/my-qemu-disk/usr/local, building and installing it with make install. This and other stuff is explained in this documentation page.

    Once you have GCC installed inside the machine, you should be able to use it as you normally do. You can now use it to compile GNU Make inside the VM, or you can just compile outside in the same way.

    For complex stuff like building kernel modules you will probably also need to build and install GNU binutils in the machine, again either from the inside with the GCC you just installed or from the outside.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文