-1

我有一个 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 上编译和运行 ac 文件。

4

2 回答 2

2

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

您必须将代码编译为从 XCode 面向 iOS SDK的静态库。的命令行选项xcodebuild-target iphoneos -arch armv7

于 2013-03-19T11:07:38.300 回答
0

在命令行上,这将为iOS编译一个未签名的通用可执行文件:

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

clang -isysroot "$(xcode-select -p)/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk" \
  -arch armv7 \
  -arch armv7s \
  -arch arm64 \
  -mios-version-min=5.0 \
  foo.c -o foo

给定foo.c

#include <stdio.h>
int main(void){printf("Hello, world!\n");return(0);}

接下来,将其 scp 到您的 JB 设备 ( scp foo mobile@name_of_iphone.local:.):

MBF:~ mobile$ ./foo
Hello, world!
MBF:~ mobile$ rm foo
MBF:~ mobile$ ^D # logout

但是你可能想把它变成一个简单的包装脚本,或者使用 xcodebuild 基础设施:

~/bin/clang_ios

#!/bin/sh
set -e
exec clang -isysroot "$(xcode-select -p)/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk" \
  -arch armv7 \
  -arch armv7s \
  -arch arm64 \
  -mios-version-min=5.0 \
  "$@"

信用

其他答案和http://clang-developers.42468.n3.nabble.com/targeting-iOS-tp4028940p4028942.html

于 2014-12-04T23:46:00.010 回答