Compiling the Linux Kernel on OS X?

Discussion in 'Mac Programming' started by linuxftw, Jul 15, 2007.

  1. macrumors newbie

    Joined:
    Jun 25, 2007
    #1
    I would like to compile the Linux kernel on OS X, as the thread title suggests.

    Would XCode, be enough to do it? Or would the version of GCC it uses not work?

    Any input would be useful, thanks :)
     
  2. Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #2
    To what end? It's not like you can replace Darwin with the Linux kernel and get OSX with a Linux core? Other than that, XCode uses gcc as it's compiler so I suppose it might well work...
     
  3. thread starter macrumors newbie

    Joined:
    Jun 25, 2007
    #3
    No I know thats not possible. Just having to use linux to compile the linux kernel is a pain for me.

    Anyway, I have had a go with the latest 2.6.5 kernel. The problem im facing is that the "-shared" option isn't available for GCC on OS X or something along those lines:

    "i686-apple-darwin8-gcc-4.0.1: unrecognized option '-shared'
    /usr/bin/ld: Undefined symbols:
    _main"

    ld returns 1 exit status, etc etc...

    Anybody know a work around?
     
  4. Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #4
    I think the problem is that you are using the OSX linker so you will be building mach-o executables. You need to build in a different executable format (probably ELF?). Maybe then you'd gain access to the options you need. But that would prevent the OSX linker from being able to work.

    Basically you need a cross compiler for x68-linux on x86-darwin...
     
  5. thread starter macrumors newbie

    Joined:
    Jun 25, 2007
    #5
    Thanks, it might be simpler for me just to compile on linux then.
     
  6. Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #6
    I think that's probably the case, yes.
     
  7. macrumors 6502

    Joined:
    Jun 1, 2006
    #7
    I've actually heard that the next iteration of iLife is going to include a graphical Linux kernel compiler, so if you wait for that, you may be in luck.

    Really though, this is an absolutely ridiculous idea. It really begs the questions as to what you're even doing compiling a kernel, when you seem to be clueless about operating system internals. Best of luck to you.
     
  8. macrumors 68040

    iSee

    Joined:
    Oct 25, 2004
    #8
    Everyone's clueless about operating system internals until they start working with them.
     
  9. macrumors 6502

    Joined:
    Jun 1, 2006
    #9
    I agree. And to learn about the internals of a specific operating system, it's useful to look into them on that operating system.
     
  10. macrumors newbie

    Joined:
    Jul 16, 2007
    #10
    Cross-compiling the Linux kernel on OS X

    We regularily cross-compile Linux kernels on OS X to various target architectures (mainly MIPS and ARM, but also sometimes to embedded PowerPC targets) and it's perfectly possible but non-trivial to get working initially.

    You will need an appropriate cross-toolchain (targeting <your-target-arch>-elf) and a number of userspace tools installed. From the top of my head, you will need ncurses for "make menuconfig", need to modify scripts/kconfig/lxdialog/check-lxdialog.sh to recognize .dylib files (again only, if you want to do a "make menuconfig"), and generally work around a lot of issues in the scripts subdirectory.

    If you are only starting with Linux kernel development, native compiles will be a lot simpler than cross-compiles, though. And Linux-hosted cross-compiles will be simpler than OS X-hosted cross-compiled.
     
  11. macrumors newbie

    Joined:
    Aug 5, 2007
    #11
    ptomisch, could you provide details on how you get the cross-compilation to work? I have been using an i686-linux-gnu cross-compiling toolchain to build work-related software on my (macbook pro) laptop, and that works great until we get to compiling the kernel (mainly module related).

    Setting ARCH and CROSS_COMPILE appropriate gets the build started, but it croaks when it tries to build scripts/mod/file2alias.c with HOSTCC. Have you just hacked your kernel source to let this build as a mach-o binary? It includes some linux kernel internal headers, which expect to have other linux-specific includes in the standard system include path.

    Thanks

    -Bill Perry

     

Share This Page