Cross compile linux on mac os

Cross-compiler for Linux on Mac OS X?

I’ve been reading lots of documents on the internet about creating a cross compiler for linux on mac os x but can’t seam to get any to work. It seams as if no one can help me with the question: Getting GMP to work with GCC 4.5.2 Is there any easy’er way to create a cross compiler?

For arm and aarch64 linux targets, I maintain precompiled OSX toolchains for download: thinkski.github.io/osx-arm-linux-toolchains

2 Answers 2

  1. install the xcode base build tools
  2. install the optional xcode command line tools
  3. install homebrew
  4. install the homebrew build tools
    4.1 brew install crosstool-ng mpfr gmp grep
    4.2 brew tap homebrew/dupes
  5. create a case sensitive volume using «disk utility»
  6. use this volume to build the tool chain itself
    6.1 generate a base configuration (for me this is an arm cortex a8)
    6.1.1 ct-ng arm-cortex_a8-linux-gnueabi
    6.2 use menuconfig (ct-ng menuconfig) to tweak the configuration
    6.2.1. disable fortran and java (c compiler)
    6.2.2. turn off static linking (c compiler)
    6.2.3. change the paths to be on the volume you created above (paths and misc options)
    6.2.4. remove dmalloc (debug facilities)
    6.3 invoke the build:
    6.3.1 ulimit -n 1024
    6.3.2 ct-ng build

with much thanks to the crosstools-ng list.

hi cxwangyi — if memory serves I did this to ensure that the volume was case sensitive. Best of luck with this. If you struggle I found the crosstools-ng list very supportive. And yes its cool 🙂

Читайте также:  Astra linux установка виртуализации

In order to build binaries for architectures different that your build host, you need far more than just a cross-compiler — you need a full-blown toolchain, which can be a real pain to create, as you probably discovered.

  • Use a proper Linux distribution in a virtual machine, such as VirtualBox. If you only want to build binaries for Linux/i386 on an MacOSX/x86_64 host, this is — in my opinion — the easiest, safest and most clean solution. It is not a cross-compiler, of course, but it works and it has the added advantage that you can actually test your executables.
  • Use a script such crosstool-NG (a descendant of the original crosstool ) to automatically build the toolchain — definitely easier than building it on your own, although you may have to compromise for slightly older compiler versions.

Linked

Hot Network Questions

Subscribe to RSS

To subscribe to this RSS feed, copy and paste this URL into your RSS reader.

Site design / logo © 2023 Stack Exchange Inc; user contributions licensed under CC BY-SA . rev 2023.7.14.43533

By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy.

Источник

How to cross compile from Mac OS X to Linux x86?

Your simplest solution is to just run CentOS 5.3 in a VM (e.g. Sun VirtualBox). This requires minimal setup, has quite reasonable overhead (assuming an Intel Mac), and you’ll be able to actually test and debug what you are building.

If you really insist on cross-compiling, you must build a cross-compiler. Instructions are here and here, but beware: it will likely take you several days to get it right, and then you’ll still need a VM to test the result, so I don’t see any point in doing it that way.

Читайте также:  Line separator in linux

There’s also crosstool-ng, however my experience with that on OS X was a bit painful in that it required building within a case-sensitive disk image (it threw a fit if it were done on a case-preserving FS as is the HFS+ default), and one has to install a number of GNU or updated versions of certain system utilities in order for it to attempt a build on OS X.

Nowadays you can probably do it with Docker for Mac, I didn’t test it because I have no mac. Docker basically creates a Linux VM and provides some nice-to-have functions.

Install docker and prepare your build image.

  • install docker
  • start a new container with docker run -ti centos5.3 /bin/bash (search the official Docker Hub for your desired target)
  • install your desired gcc version (something like sudo yum group install «Development Tools» )
  • exit your container
  • run docker ps -a to obtain your container id
  • backup your container as base build image docker commit [id] centos:build

Make a build

Now you can use your created build environment for CentOS builds.

  • to start your build environment while mounting the working directory inside it you can use something like docker run -it —mount type=bind,source=$(pwd),target=/mnt centos:build /bin/sh -c «cd /mnt && bash»
  • then run gcc . or ./configure or make or ninja or whatever to do your build
  • you can also run automated tests here if you wrote some

Docker vs VM

With docker you can use your beloved terminal with your familiar theme and keymap. Furthermore it most probably will consume less resources for startup and while running.

Читайте также:  Wps office linux russian language pack

If your app is graphical and you test it by using interaction with its GUI I guess a VM is still a better option (see @employed-russian’s solution).

Источник

Оцените статью
Adblock
detector