Cross compilation issues¶. In GCC world, every host/target combination has its own set of binaries, headers, libraries, etc. So, it’s usually simple to download a package with all files in, unzip to a directory and point the build system to that compiler, that will know about its location and find all it needs to when compiling your code. Cross-compiling Chrome/win. As many Chromium developers are on Linux/Mac, cross-compiling Chromium for Windows targets facilitates development for Windows targets on non-Windows machines. It‘s possible to build most parts of the codebase on a Linux or Mac host while targeting Windows. Using these two, we can compile a program in a Mac that will run on that Linux like this: crystal build yourprogram.cr -cross-compile -target 'x8664-unknown-linux-gnu' This will generate a.o ( Object file ) and will print a line with a command to execute on the system we are trying to cross-compile to. TakeoffGW is a distribution of Unix tools for Windows, built by cross-compiling on a Linux machine. They would like to be able to build and distribute GHC this way. It might be useful for us to be able to cross-compile a Windows GHC from Linux too. Build a 64-bit GHC on OS X, by cross-compiling.
![Cross Compiling For Linux On Mac Cross Compiling For Linux On Mac](/uploads/1/3/4/7/134783462/784160336.png)
Crystal supports a basic form of cross compilation.
Compile Linux Application
In order to achieve this, the compiler executable provides two flags:
![Cross compiling for mac os x on linux Cross compiling for mac os x on linux](https://dzone.com/sites/all/files/titanium arch.png)
--cross-compile
: When given enables cross compilation mode--target
: the LLVM Target Triple to use and set the default compile-time flags from
Cross Compiling For Linux On Mac Windows 10
To get the
--target
flags you can execute llvm-config --host-target
using an installed LLVM 3.5. For example on a Linux it could say 'x86_64-unknown-linux-gnu'.If you need to set any compile-time flags not set implicitly through
--target
, you can use the -D
command line flag.Using these two, we can compile a program in a Mac that will run on that Linux like this:
This will generate a
.o
(Object file) and will print a line with a command to execute on the system we are trying to cross-compile to. For example:You must copy this
.o
file to that system and execute those commands. Once you do this the executable will be available in that target system.This procedure is usually done with the compiler itself to port it to new platforms where a compiler is not yet available. Because in order to compile a Crystal compiler we need an older Crystal compiler, the only two ways to generate a compiler for a system where there isn't a compiler yet are:
- We checkout the latest version of the compiler written in Ruby, and from that compiler we compile the next versions until the current one.
- We create a
.o
file in the target system and from that file we create a compiler.
Cross Compile For Linux On Mac
The first alternative is long and cumbersome, while the second one is much easier.
Cross-compiling can be done for other executables, but its main target is the compiler. If Crystal isn't available in some system you can try cross-compiling it there.