登录 用户中心() [退出] 后台管理 注册
   
您的位置: 首页 >> CLQ工作室开源代码 >> 主题: xcode 12 下必须要用 -isysroot 参数     [回主站]     [分站链接]
标题
xcode 12 下必须要用 -isysroot 参数
clq
浏览(407) + 2021-04-30 13:11:49 发表 编辑

关键字:

[2021-05-04 10:53:42 最后更新]
编译为 ios 的跨平台版本时目前必须设置这个参数为正确的路径

而且更为严重的是,之前 xcode 10 下没有加这个参数编译出的 .a 静态库,在 xcode 12 下也会用不了,即使之前一直工作正常。
我是在编译 x264 的时候发现这个问题的,试了好久才发现是这个参数影响的。而我之前是用的 -I 参数。
另外 xcode 下的 -L 参数似乎是无效的,应该是要使用 --sysroot= 这个参数? 未证实,大家当做一个知识点就好。
----------------------------------------------------------------


#!/bin/sh

# 如果编译平台失败的话,在生成 .o 文件的时候就会出错,所以写一个生成 .o 的脚本先测试平台参数是否正确


#---------------------------------------------------------------
#奇怪的是,什么参数都不加的话反而编译是成功的

#export CC=`xcodebuild -find clang`
#export CC=`/Users/ccc/Desktop/1/Xcode.app/Contents/Developer/usr/bin/gcc`
#export CC=/Users/horseming/Desktop/1/Xcode.app/Contents/Developer/usr/bin/gcc
export CC=/Users/ccc/Desktop/1/Xcode.app/Contents/Developer/usr/bin/gcc

# xcode 10 可以用这个
#gcc -c gcc_cross_test1.c -arch arm64 -I/Users/ccc/Desktop/1/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/usr/include -L/Users/ccc/Desktop/1/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/usr/lib


gcc -c gcc_cross_test1.c -arch arm64 -I/Users/ccc/Desktop/1/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/usr/include -isysroot /Users/ccc/Desktop/1/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk -fembed-bitcode

#xcode 12.3 下必须要用 -isysroot 参数,原来 xcode 中可用的 -L 已经不行了,奇怪的是并不需要 --sysroot= 这个参数。

clq
2021-04-30 13:13:08 发表 编辑

参考 https://blog.csdn.net/tangsilian/article/details/94504703

---------------------------------------------------------------------
在macOS上交叉编译arm64的程序并在IOS上运行
tangsilian 2019-07-03 01:00:55 3028 收藏
分类专栏: # 2 IOS安全
版权
0x01 两种编译方式如下:

简单编写一个demo.c

#include
int main()
{
printf("i am include");
return 0;
}

1
2
3
4
5
6

第一种使用-isysroot指定头文件

// -arch 表示要编译的架构 这里为armv7.
// -isysroot 指定头文件的根路径
clang -arch arm64 -o demo demo.c -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk

1
2
3

第二种使用xcrun -sdk

xcrun -sdk iphoneos clang -arch arm64 -o demo demo.c //xcrun -sdk 会使用最新的sdk去编译

1

使用file命令查看编译出来的文件是什么架构

✗ file demo
demo: Mach-O 64-bit executable arm64

0x02 使用scp拷贝到iphone中

使用scp把编译出的demo拷贝在iphone的/tmp目录下(端口默认是22)

scp demo root@iphoneip : /tmp/demo

执行出现 kill -9的错误
在这里插入图片描述
后面发现是可执行的文件未签名的原因才会出现kill -9
0x03 给可执行文件签名

codesign给它签名

codesign -s “A2F872A1D9483EA7E16E6836CDF73B7917010A20” --entitlements demo.entitlements -f demo

其中A2F872A1D9483EA7E16E6836CDF73B7917010A20 可以通过/usr/bin/security find-identity -v -p codesigning指令获取
在这里插入图片描述
demo.entitlements文件内容如下




com.apple.springboard.debugapplications

get-task-allow

proc_info-allow

task_for_pid-allow

run-unsigned-code

platform-application




1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17

签名前后的对比:

codesign -dvvv demo
或者codesign --display --verbose=4 demo
在这里插入图片描述

拷贝文件到手机中执行前后对比如下:
在这里插入图片描述
0x04 命令行编译OC

xcrun -sdk iphoneos clang -framework Foundation -arch arm64 hello.m -o hello

#include
#include
#include
#import

@interface Talker : NSObject

- (void) say: (NSString*) phrase;

@end


@implementation Talker

- (void) say: (NSString*) phrase {
NSLog(@"%@\n", phrase);
}

@end



int main(void) {

Talker *talker = [[Talker alloc] init];
[talker say: @"Hello, Ice and Fire!"];
[talker say: @"Hello, Ice and Fire!"];
[talker release];

}

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30

也需要签名

参考:
http://ourui.github.io/2014/09/12/2014-09-12-clang-compile-arm-file/
http://iosre.com/t/ios11-iphone-tool-killed-9-killed/12819
用命令行编译iPhone app
https://commandlinefanatic.com/cgi-bin/showarticle.cgi?article=art024
用clang编译C语言及OC小记
https://www.mobilezhao.com/?p=507
————————————————
版权声明:本文为CSDN博主「tangsilian」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/tangsilian/article/details/94504703




clq
2021-05-04 10:53:42 发表 编辑

不过对于我的 x264 编译环境来说(各个软件的版本差异应该比较大)xcode10 下反而加 isysroot 是错误的。


总数:2 页次:1/1 首页 尾页  
总数:2 页次:1/1 首页 尾页  


所在合集/目录
ffmpeg 更多
c语言编译专题 更多
xcode编译专题 更多
ios编译专题 更多



发表评论:
文本/html模式切换 插入图片 文本/html模式切换


附件:



NEWBT官方QQ群1: 276678893
可求档连环画,漫画;询问文本处理大师等软件使用技巧;求档softhub软件下载及使用技巧.
但不可"开车",严禁国家敏感话题,不可求档涉及版权的文档软件.
验证问题说明申请入群原因即可.

Copyright © 2005-2020 clq, All Rights Reserved
版权所有
桂ICP备15002303号-1