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

后端 未结 5 955
眼角桃花
眼角桃花 2020-11-29 05:27

I\'m running Mac OS X 10.5.8 and want to compile for target CentOS 5.3 with GCC 4.1.2. How could I:

  1. Compile GCC 4.1.2 toolchain and related tools?
  2. Use
5条回答
  •  抹茶落季
    2020-11-29 05:56

    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.

    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).

提交回复
热议问题