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

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:
Compile GCC 4.1.2 toolchain and related tools?
Use that tool to cross compile for target CentOS 5.3?
Any help is greatly appreciated!

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.

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

Use Cocotron to cross-compile directly from Xcode. There's a good getting-started guide here: http://blog.tlensing.org/tag/cocotron/

I struggled to get crosstool-ng to build on OSX 10.9 for x86_64 Linux. I used the very helpful post on how to build a gcc cross-compiler by Jeff Preshing and his script here as the basis for a script that worked for me. His script in the link doesn't work when compiling glibc on my version of OSX (which seems to be a very common complaint for those cross-compiling from OSX to Linux).
My script is here: https://github.com/johnlondon/Cross-compile-toolchain-for-linux-on-OSX

You can use crosstool-ng, or if you don't want to spend too much time to configure it, you can download a pre-configured cross-compiler, as Linaro.
Here's the guide for installing it in Mac OS X.

Related

Prometheus pre build binary for Mac OS X

I am trying out Prometheus on Mac OS X. I looked up the downloads and not having a direct indication of which version is for Mac. I tried docker to run the Prometheus on Mac. Just want to run it directly on Mac without docker. Does any one know which version to pick.
There were few BSDs there for pick. I know Mac is also BSD. Not sure which one matches or doesn't matter as long as it is bsd?.
Other than those binaries, I think brew install should do the work
The downloads page has a build for Darwin on amd64.
To quote the wikipedia page:
Darwin forms the core set of components upon which macOS (previously
OS X and Mac OS X), iOS, watchOS, and tvOS are based.
This is the official binary for OSX. Other methods (such as brew install prometheus are also available).
Install and download Docker from this link - https://docs.docker.com/v17.12/docker-for-mac/install/#download-docker-for-mac.
You can launch the your terminal.
You can launch a Prometheus container for trying it out with
$ docker run --name prometheus -d -p 127.0.0.1:9090:9090 prom/prometheus
Prometheus will now be reachable at http://localhost:9090/.

How does docker run on osx, does it use vagrant?

I use an older model MB Air and running vagrant is very resource intensive for me.
When using docker on OSX, does it just use vagrant behind the scenes to run my docker instance on ubuntu?
In contrast to the deprecated Docker Toolbox (which also runs on MacOS), recent versions of Docker for Mac do not use VirtualBox, but rather HyperKit, a native MacOS hypervisor, which is built on xhyve. In comparison to VirtualBox, HyperKit claims to be more lightweight.
Also consider the official documentation on the differences and interna of Docker Toolbox and Docker for Mac (emphasis mine):
Docker for Mac is a Mac native application, that you install in /Applications. [...]
Here are some key points to know about Docker for Mac before you get started:
Docker for Mac does not use VirtualBox, but rather HyperKit, a lightweight macOS virtualization solution built on top of Hypervisor.framework in macOS 10.10 Yosemite and higher. [...]
The Docker for Mac application does not use docker-machine to provision that VM; but rather creates and manages it directly.
At installation time, Docker for Mac provisions an HyperKit VM based on Alpine Linux, running Docker Engine. It exposes the docker API on a socket in /var/run/docker.sock. Since this is the default location where docker will look if no environment variables are set, you can start using docker and docker-compose without setting any environment variables.
[...]
With Docker for Mac, you get only one VM, and you don’t manage it. It is managed by the Docker for Mac application, which includes autoupdate to update the client and server versions of Docker.
It doesn't use Vagrant, but it there is underlying VirtualBox machine similar to what Vagrant uses. Things might be slightly better with Docker because the docker VM is very slimmed down version. And you can pack multiple images into that VM in more efficient manner, because they will be using the same kernel and IO layers.
Also, note that with both Vagrant and Docker you can use AWS or similar cloud things to actually run your images.

Can I use CircleCI with other OS than Ubuntu?

Is it possible to use CircleCI with other OS than Ubuntu? I can't find an answer in the documentation.
Particularly I would like to use Debian 7.8.
You can use a Docker image of Debian 7.8 inside your build, but it's not possible at this time to replace the base image of the build VM.

Cross compiling on mac for windows

Can I compile on mac so it will produce a windows binary? bind with windows dlls? (I have a windows machine to copy them from) How can I do so? clang and gcc are the compilers I can use.
These instructions will work on both MacOS and Linux, but I will provide them from a Mac perspective.
Download Docker
Add a Windows dockcross
If you don't know how to use docker then just download Kitematic (Links to an external site.).
From Kitematic you can simply click the "+New" button and get the dockcross image from the docker hub.
After the image downloads in Kitematic, click the "Docker CLI" button in the bottom left. This will open a new terminal window setup for the docker environment.
From that terminal window:
cd to the directory with the project you want to build then save a shellscript that will run the docker container and build the project:
docker run --rm dockcross/windows-x86 > ./dockcross
chmod +x ./dockcross
./dockcross make (assuming your project uses a makefile)
See the dockcross documentation for more examples and further guidance.
dockcross uses MXE, so you can pretty easily build most projects, but you may need to install additional MXE packages
The MinGW's toolchain can be built on OSX or most other unix/unix-like operating systems.
Here's a link to the precompiled binaries: http://crossgcc.rts-software.org/doku.php?id=mingw-older-releases
It works fine on my PowerMac G5 and as keith.layne says there is also a solution for Intel Macs.

How can I build an RPM on my MacOS system?

I'm running Mac OS X 10.6.6. I have some data-only RPMs that I'd like to build.
Until recently I've done most of my development on a VM running CentOS, but one by one I've been able to transition these tasks to the Mac proper. I've been using Fink to access the Open/Free tools I need, but I'm not ready to go to Fink unstable, where the RPM5 package has been for a while.
I've also tried to build the RPM utilities from source, with little luck so far.
Is anyone else building RPMs natively on a Mac? If so, how?
You can install rpmbuild on MacOS using Homebrew package manager.
brew install rpm
This installs a bunch of packages including rpmbuild which is used to build an rpm. You can then run the following command to create an rpm
rpmbuild <specfile>
I was in this same situation today, but I've just successfully built and run rpm by first installing MacPorts and then installing from there. It requires an absolutely ludicrous 1.8GB of downloads before you can even build because it requires installing the (free) Xcode developer tools package from the Apple Store at 1.6GB, then another 140MB package of command line tools.
So, first carefully follow every step of the clear instructions here to install MacPorts:
http://www.macports.org/install.php
After doing all that, be sure to run the update command (as mentioned in the install instructions) so that it downloads the available software ports package (it'll say "can't find rpm" if you don't):
sudo port -v selfupdate
Once all that is done, run the following to fetch rpm and build it:
sudo port install rpm
On my early 2011 MacBook Pro with Lion, it took about 10 minutes to download everything and build.
The whole process takes a while, but it works. Good luck!
As #user132447 pointed out, you will need to reformat the drive to MacOS extended (case sensitive).
The rpm which is part of CentOS is different then the RPM5 build. Both are two different projects. And later may work on MacOS, but I would recommend you to go using VMs (or separate systems) which are RPM based only. That will surely save you long hours of fixing and caring about not so useful issues.
RPM from rpm.org doesn't support MacOS yet (it builds I guess - at least the latest version), and this is the rpm which CentOS uses.
I've been using RPM for Darwin for building maven based projects that create RPM artifacts.

Resources