Cross-compilation
In order to achieve this, the compiler executable provides two flags:
- : When given enables cross compilation mode
To get the --target
flags you can execute using an installed LLVM 3.5. For example on a Linux it could say “x86_64-unknown-linux-gnu”.
Using these two, we can compile a program in a Mac that will run on that Linux like this:
This will generate a (Object file) and will print a line with a command to execute on the system we are trying to cross-compile to. For example:
cc your_program.o -o your_program -lpcre -lrt -lm -lgc -lunwind
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 create a file in the target system and from that file we create a compiler.
The first alternative is long and cumbersome, while the second one is much easier.