2013-12-15 19:06:50 +01:00
## OS X Cross toolchain for Linux and FreeBSD ##
2013-11-13 20:47:04 +01:00
### WHAT IS THE GOAL OF OSXCROSS? ###
2013-12-15 19:06:50 +01:00
The goal of OSXCross is to provide a well working OS X cross toolchain for Linux and FreeBSD.
2013-11-13 20:47:04 +01:00
### HOW DOES IT WORK? ###
2013-11-13 22:59:39 +01:00
[Clang/LLVM is a cross compiler by default ](http://clang.llvm.org/docs/CrossCompilation.html ) and is now available on nearly every Linux distribution.
2013-11-13 20:47:04 +01:00
Therefore we "just" need a proper
2013-12-15 19:06:50 +01:00
[port ](https://github.com/tpoechtrager/cctools-port )
2013-11-13 20:47:04 +01:00
of the [cctools ](http://www.opensource.apple.com/tarballs/cctools ) (ld, lipo, ...) for Linux, and the OS X SDK.
If you want, then you can build an up-to-date vanilla GCC as well.
### WHAT IS NOT WORKING (YET)? ###
2013-12-15 19:06:50 +01:00
* Debug info is weak, because of the [missing ](https://github.com/tpoechtrager/osxcross/blob/master/patches/gcc-dsymutil.patch )
2013-11-13 20:47:04 +01:00
[`dsymutil` ](http://www.manpagez.com/man/1/dsymutil ) (shows only function names, no line numbers)
2013-12-15 19:06:50 +01:00
* GCC itself [doesn't build with GCC ](https://github.com/tpoechtrager/osxcross/commit/12f5dcdde4bc1000180d25ffda229f0a13cf723d ),
but builds fine when clang is used to build GCC
2013-11-13 20:47:04 +01:00
Everything else besides that should work.
### WHAT CAN I BUILD WITH IT? ###
Basically everything you can build on OS X with clang/gcc should build with this cross toolchain as well.
### INSTALLATION: ###
2013-11-16 18:36:44 +01:00
Download the SDK version (links below) you want to the tarball/ (important!) directory.
2013-11-13 20:47:04 +01:00
2013-12-16 18:17:09 +01:00
Then ensure you have the following installed on your Linux box:
2013-11-13 20:47:04 +01:00
`Clang 3.2+` , `llvm-devel` , `automake` , `autogen` , `libtool` ,
2013-12-15 19:06:50 +01:00
`libxml2-devel` (< =10.5 only), `uuid-devel` , `openssl-devel` and the `bash shell` .
Hint: On Ubuntu 12.04 LTS you can use [llvm.org/apt ](http://llvm.org/apt ) to get a newer version of clang.
2013-11-13 20:47:04 +01:00
Now edit the `SDK_VERSION` in `build.sh` , so it matches the version you have downloaded before.
Then run `./build.sh` to build the cross toolchain (It will build in it's own directory).
2013-12-15 19:06:50 +01:00
**Don't forget** to add the printed `` `<path>/osxcross-env` `` to your `~/.profile` or `~/.bashrc` .
2013-11-13 20:47:04 +01:00
Then either run `source ~/.profile` or restart your shell session.
2013-12-15 19:06:50 +01:00
That's it. See usage examples below.
##### Building libc++: #####
If you want to build libc++ for modern C++11 with clang, then you can do this by running `./build_libcxx.sh` .
The resulting library will be linked statically into the applications, to avoid troubles with different
libc++.dylib versions on OS X.
See below in how to use libc++ as the standard library.
2013-11-13 20:47:04 +01:00
##### Building GCC: #####
If you want to build GCC as well, then you can do this by running `./build_gcc.sh` .
But before you do this, make sure you have got the gcc build depedencies installed on your system,
2013-12-15 19:06:50 +01:00
on debian like systems you can run `apt-get install mpc-dev mpfr-dev gmp-dev` to install them.
2013-11-13 20:47:04 +01:00
### SDK DOWNLOAD LINKS: ###
2013-11-13 21:21:05 +01:00
### USAGE EXAMPLES: ###
2013-11-13 20:47:04 +01:00
##### Let's say you want to compile a file called test.cpp, then you can do this by running: #####
* Clang:
2013-11-13 21:21:05 +01:00
* 32 bit: `o32-clang++ test.cpp -O3 -o test` OR `i386-apple-darwinXX-clang++ test.cpp -O3 -o test`
* 64 bit: `o64-clang++ test.cpp -O3 -o test` OR `x86_64-apple-darwinXX-clang++ test.cpp -O3 -o test`
2013-11-13 20:47:04 +01:00
* GCC:
2013-11-13 21:21:05 +01:00
* 32 bit: `o32-g++ test.cpp -O3 -o test` OR `i386-apple-darwinXX-g++ test.cpp -O3 -o test`
* 64 bit: `o64-g++ test.cpp -O3 -o test` OR `x86_64-apple-darwinXX-g++ test.cpp -O3 -o test`
2013-11-13 20:47:04 +01:00
2013-11-13 20:57:28 +01:00
XX= the target version, you can find it out by running `osxcross-conf` and then see `TARGET` .
2013-11-13 20:47:04 +01:00
2013-11-13 22:59:39 +01:00
You can use the shortcut `o32-...` or `i386-apple-darwin...` what ever you like more.
2013-11-13 20:47:04 +01:00
2013-11-13 21:21:05 +01:00
*I'll continue from now on with `o32-clang` , but remember you can simply replace it with `o32-gcc` or `i386-apple-darwin...` .*
2013-11-13 20:47:04 +01:00
##### Building Makefile based projects: #####
2013-11-13 20:57:28 +01:00
* `make CC=o32-clang CXX=o32-clang++`
2013-11-13 20:47:04 +01:00
##### Building automake based projects: #####
2013-11-13 20:57:28 +01:00
* `CC=o32-clang CXX=o32-clang++ ./configure --host=i386-apple-darwinXX`
2013-11-13 20:47:04 +01:00
2013-12-15 19:06:50 +01:00
##### Building test.cpp with libc++: #####
* Clang:
* C++98: `o32-clang++ -stdlib=libc++ test.cpp -o test`
* C++11: `o32-clang++ -stdlib=libc++ -std=c++11 tes1.cpp -o test`
* C++1y: `o32-clang++ -stdlib=libc++ -std=c++1y test1.cpp -o test`
* Clang (shortcut):
* C++98: `o32-clang++-libc++ test.cpp -o test`
* C++11: `o32-clang++-libc++ -std=c++11 test.cpp -o test`
* C++1y: `o32-clang++-libc++ -std=c++1y test.cpp -o test`
* GCC (defaults to C++11 with libc++)
* C++11: `o32-g++-libc++ test.cpp`
* C++1y: `o32-g++-libc++ -std=c++1y test.cpp -o test`
2013-11-13 20:47:04 +01:00
##### Building test1.cpp and test2.cpp with LTO (Link Time Optimization): #####
* build the first object file: `o32-clang++ test1.cpp -O3 -flto -c`
* build the second object file: `o32-clang++ test2.cpp -O3 -flto -c`
* link them with LTO: `o32-clang++ -O3 -flto test1.o test2.o -o test`
##### Building a universal binary: #####
2013-12-15 19:06:50 +01:00
* Clang:
2013-11-13 20:52:07 +01:00
* `o64-clang++ test.cpp -O3 -arch i386 -arch x86_64 -o test`
* GCC:
2013-11-13 20:47:04 +01:00
* build the 32 bit binary: `o32-g++ test.cpp -O3 -o test.i386`
* build the 64 bit binary: `o64-g++ test.cpp -O3 -o test.x86_64`
* use lipo to generate the universal binary: `x86_64-apple darwinXX-lipo -create test.i386 test.x86_64 -output test`
### LICENSE: ####
* bash scripts: GPLv2
* cctools: APSL 2.0
* xar: New BSD
### CREDITS: ####
* [cjacker for the cctools linux port ](https://code.google.com/p/ios-toolchain-based-on-clang-for-linux/source/browse/#svn%2Ftrunk%2Fcctools-porting%2Fpatches )