0

我正在尝试使用命令行将 mach-o arm 目标文件编译为 mach-o arm 可执行文件。我使用过像这样的各种命令

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

它们都返回不同的错误,说明编译错误的架构或缺少必要的文件。我需要正确编译它的命令是什么?

4

1 回答 1

0

默认编译器(您的 中的编译器$PATH)引用可以为您的本地计算机编译的编译器。您需要一个知道如何创建 ARM 二进制文件的交叉编译器。如果你已经安装了带有 iOS SDK 的 Xcode,你可以使用例如:

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

或者

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

例如,在我的机器上:

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

如果我然后运行,file test我会得到:

test: Mach-O executable arm
于 2013-08-12T10:59:49.177 回答