0

Im trying to compile a mach-o arm object file to mach-o arm executable using the command line. I have used various commands like these

clang -arch armv7 helloapp.o -o helloapp
clang helloapp.o -o helloapp
gcc helloapp.o -o helloapp

They all return different errors saying compiling for wrong architecture or missing neccessary files. What is the command I need to compile this properly??

walsh06
  • 97
  • 1
  • 9

1 Answers1

0

The default compilers (the ones in your $PATH) reference the ones that can compile for your local machine. You need a cross-compiler that knows how to create ARM binaries. If you've got Xcode with iOS SDK installed you can use for example:

PATH_TO_Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc

or

PATH_TO_Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang

For example, on my machine:

ARM_GCC=~/Documents/Xcode4.6.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc
IOS_SDK=~/Documents/Xcode4.6.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.1.sdk

# Compile
$ARM_GCC -arch armv7 -c test.c -o test.o
# Link
$ARM_GCC -arch armv7 -isysroot "$IOS_SDK" test.o -o test

If I then run file test I get:

test: Mach-O executable arm
DarkDust
  • 90,870
  • 19
  • 190
  • 224
  • Im still getting the same errors telling me "file was built for armv7 which is not the architecture being linked" – walsh06 Aug 12 '13 at 11:09
  • You need to also pass `-arch armv7` when linking! And set the `isysroot` accordingly. See my updated answer. – DarkDust Aug 12 '13 at 11:29
  • ok thats certainly working better than before. I got an error though "ld: library not found for -lcrt1.o" – walsh06 Aug 12 '13 at 11:39