Reputation: 171
I know that if I want to compile a program for an ARM device I need a special version of gcc that runs under x86 and compiles for ARM (cross compiling) is there a way to compile for ARM under ARM?
Upvotes: 3
Views: 2495
Reputation: 1192
Recent Debian for Raspberry Pi 2 came with gcc 4.6. For more advanced features, such as for NEON, you can install gcc 4.8, or later. Example compile commands for different FPU options are:
gcc 4.6
gcc linpack.c cpuidc.c -lm -lrt -O3 -march=armv6 -mfloat-abi=hard -mfpu=vfp -o linpackPiA6
gcc 4.8
gcc linpack.c cpuidc.c -lm -lrt -O3 -mcpu=cortex-a7 -mfloat-abi=hard -mfpu=neon-vfpv4 -o linpackPiA7
Upvotes: 0
Reputation: 2491
If you are happy to compile from source, any recent version of GCC can be built natively on an ARM device, targeting that ARM device. The dependencies to compile GCC and the size of the code base might give you some difficulties, but I regularly build the up-to-date GCC development branch on my Raspberry Pi 2.
Follow the instructions at: https://gcc.gnu.org/install/ to get the prerequisites you need, and when configuring the compiler use something like:
--with-cpu=cortex-a15 --with-float=hard --with-fpu=neon --with-mode=thumb
Modifying the --with-cpu
and --with-fpu
options as required for your system.
If you are looking for prebuilt binaries, most distributions (and certainly Debian and Ubuntu) which run on ARM will provide you with a package you can install, just like your x86 systems.
Upvotes: 6
Reputation: 71586
yes there are cross compilers and yes there are native compilers. You can for example buy a raspberry pi and install one of the canned distros and that gives you a native compiler, or you can for example use qemu and run an arm distro built for one of the many systems supported by qemu simulations (and run a native compiler on that)...or just cross compile.
Upvotes: 1
Reputation: 12515
Consider downloading the source code for the compiler of your choice. Here is a location that contains the source you could attempt to use.
I could see one using, on an x86 box to start, an x86 cross compiler to compile the ARM version of the compiler for your local ARM based system. Then you can use the native version going forward on your system.
Upvotes: 1