在iPhone中编译和执行C程序

在iPhone中编译和执行C程序,iphone,ios,c,compilation,Iphone,Ios,C,Compilation,我有一个C程序,它使用ASL库获取iPhone上应用程序的日志。现在,我已经在Mac上编译了这个程序,它运行良好,获取了Mac上应用程序的日志。。当我将编译后的文件scp到iPhone并尝试执行它时,它会显示“可执行文件中的cpu类型错误”。所以,我在iPhone上安装了GNU C编译器并编译了它。。现在,当我编译它时,它会显示如下错误: cP-iphone:~ root# gcc test.c test.c:1:19: error: stdio.h: No such file or direc

我有一个C程序,它使用ASL库获取iPhone上应用程序的日志。现在,我已经在Mac上编译了这个程序,它运行良好,获取了Mac上应用程序的日志。。当我将编译后的文件scp到iPhone并尝试执行它时,它会显示“可执行文件中的cpu类型错误”。所以,我在iPhone上安装了GNU C编译器并编译了它。。现在,当我编译它时,它会显示如下错误:

cP-iphone:~ root# gcc test.c
test.c:1:19: error: stdio.h: No such file or directory
test.c:2:17: error: asl.h: No such file or directory
test.c: In function 'main':
test.c:5: warning: incompatible implicit declaration of built-in function 'printf'
test.c:16: error: 'aslmsg' undeclared (first use in this function)
test.c:16: error: (Each undeclared identifier is reported only once
test.c:16: error: for each function it appears in.)
test.c:16: error: expected ';' before 'q'
test.c:21: error: 'q' undeclared (first use in this function)
test.c:21: error: 'ASL_TYPE_QUERY' undeclared (first use in this function)
test.c:22: error: 'ASL_KEY_SENDER' undeclared (first use in this function)
test.c:22: error: 'ASL_QUERY_OP_EQUAL' undeclared (first use in this function)
test.c:23: error: 'aslresponse' undeclared (first use in this function)
test.c:23: error: expected ';' before 'r'
test.c:24: error: 'NULL' undeclared (first use in this function)
test.c:24: error: 'm' undeclared (first use in this function)
test.c:24: error: 'r' undeclared (first use in this function)
test.c:27: warning: assignment makes pointer from integer without a cast
test.c:30: warning: assignment makes pointer from integer without a cast

请建议我需要做什么,以便在iPhone上编译并运行c文件。

在模拟器和mac上,您可以运行i386代码。但你不能在真正的设备上,因为它是一个不同的处理器


您必须将代码编译为一个静态库,目标是来自XCode的iOS SDK。
xcodebuild
的命令行选项是在命令行上的
-target iphoneos-arch armv7
,这将为iOS编译一个未签名的通用可执行文件:

(因此,它将只在已越狱的真实设备上执行,或以某种方式从已签名的应用程序启动(可能使用IAS中不允许的调用)。)

clang-isysroot“$(xcode-select-p)/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk”\
-拱臂7\
-ArchV7S\
-拱臂64\
-mios版本最小值=5.0\
foo.c-o foo
给定
foo.c

#包括
int main(void){printf(“你好,世界!\n”);返回(0);}
接下来,将其scp到您的JB'ed设备(
scp-foomobile@name_of_iphone.local:。
):

但您可能希望将其转换为一个简单的包装器脚本,如这样,或者使用xcodebuild基础架构:

~/bin/clang\u ios
#/垃圾箱/垃圾箱
set-e
exec clang-isysroot“$(xcode select-p)/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk”\
-拱臂7\
-ArchV7S\
-拱臂64\
-mios版本最小值=5.0\
"$@"
信用
其他答案和

如果有人投了反对票,请留下一条奇怪的评论,说明你为什么投反对票!你似乎有一个越狱装置,并应用破胶配方。您是在寻找越狱设备的具体答案,还是更一般的答案?如果是这样的话,你应该将你的问题重新表述为避免在设备上使用
scp
gcc
…你是否提供了-arch-armv7和-isysroot/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.2.sdk到gcc?@StephaneDelcroix当我提到scp时,显然意味着我想要它作为越狱设备!!
MBF:~ mobile$ ./foo
Hello, world!
MBF:~ mobile$ rm foo
MBF:~ mobile$ ^D # logout