在Mac OS X上构建Linux内核 [英] building Linux kernel on Mac OS X

查看:465
本文介绍了在Mac OS X上构建Linux内核的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在做一个修改Linux内核的项目.我有一台台式机Linux机器,并且在其上构建内核也没有问题.

I am doing a project to modify the Linux kernel. I have a desktop Linux machine and I have no problem building kernel on it.

但是,我要去旅行了,所以我想按自己的方式工作.我只有一台MacBook.当我尝试构建Linux内核时,它抱怨elf.h was not found.

However, I am going on a trip and I want to work on my way. I only have a MacBook. When I tried to build the Linux kernel, it complained that elf.h was not found.

我从互联网上下载了elf.h.现在它抱怨:NO ELF

I download an elf.h from internet. Now it complains: NO ELF

我尝试从Linux桌面复制整个/usr/include,并将其设置为include目录,但仍然出现类似"u8" not declared

I tried copying the entire /usr/include from my Linux desktop, and set it as the include directory, and still get strange errors like "u8" not declared

在Mac上进行内核开发的标准方法是什么?我有一个在同一Mac上运行Linux的虚拟机,它将用于测试修改后的内核.但是,我真的不想在其上构建内核,因为它有点慢.

What is the standard way of doing kernel development on Mac? I have a virtual machine running Linux on the same Mac, and it will be used to test the modified kernel. However, I don't really want to build kernel on it, as it is kinda slow.

推荐答案

首先,我同意仅使用Linux VM通常更简单.就是说,如果您真的想要这样做,我已经使用以下过程成功编译了Linux内核代码.

First, I agree that it's usually simpler to just use a Linux VM. That said, if you really want to do this, I have successfully compiled Linux kernel code using the procedure below.

在甚至可以开始之前,可能需要在Mac上区分大小写的文件系统上安装Linux源代码树. (默认的HFS文件系统不区分大小写.)在这里我不会介绍,但是很多人这样做是为了编译Android源代码树,因此

Before you can even start, you may need to install the Linux source tree on a case-sensitive filesystem on your Mac. (the default HFS filesystem is case insensitive.) I won't cover that here, but a lot of people do this to compile the Android source tree, so you can use Google to find instructions.

首先,您需要以下文件才能在OS X盒上交叉编译内核(将它们从已知正常工作的Linux VM复制到本地/usr/include):

First you'll need the following files to cross-compile a kernel on an OS X box (copy them from your known-working Linux VM to your local /usr/include):

/usr/include/elf.h
/usr/include/features.h
/usr/include/bits/predefs.h
/usr/include/bits/wordsize.h
/usr/include/gnu/stubs.h
/usr/include/gnu/stubs-64.h

接下来,您需要将malloc.h放在Linux系统的预期位置,所以这样做:

Next you'll need malloc.h to be in the expected location for a Linux system, so do:

sudo ln -s /usr/include/malloc/malloc.h /usr/include/malloc.h

最后,您需要担心系统上安装的编译器是否适合构建Linux内核.我已使用适当的交叉编译器工具链将此步骤用于为Android编译的内核,但是我不确定是否可以在OS X上使用默认的gcc编译器成功编译Linux内核(假设您拥有Xcode随附...)

Finally, you'll need to worry about whether or not the compiler installed on your system is suitable for building the Linux kernel. I have used this procedure for kernels compiled for Android, using an appropriate cross-compiler toolchain, but I'm not sure if you can successfully compile a Linux kernel with the default gcc compiler on OS X (assuming you have the one that comes with Xcode...)

编辑:您可能还想按照上述注释中链接的bug(从"nmagerko"中指出)中指出的步骤进行操作,以确保您具有正确的依赖关系以及.特别是:

EDIT: You may also want to follow the steps pointed out in the bug linked in the comment above from "nmagerko", to ensure you have the correct dependencies, and the GNU version of sed. In particular:

$ sudo port install libelf
$ sudo port install gsed

这篇关于在Mac OS X上构建Linux内核的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆