10.14版macOS.sdk编译32位可执行文件

一、背景介绍

The macOS 10.14 SDK no longer contains support for compiling 32-bit applications. If developers need to compile for i386, Xcode 9.4 or earlier is required. (39858111)
Apple has announced that its upcoming macOS Mojave release for Macs will officially be the last to support 32-bit apps.

大意:
中央已经决定了!从现在开始禁止编译32位的 mac 上的可执行文件!下一个大版本起,任何人都不得运行32位的可执行文件。

参考链接:https://developer.apple.com/documentation/xcode_release_notes/xcode_10_release_notes
 

 

二、基本原理

xcode-select命令用于管理 /usr/bin/gcc 等常用的开发者工具,即Command Line Tools,检查其是否存在,有时候会跟 Xcode 一起被安装,也可以单独存在。其中有一个基础属性,用来指定Command Line Tools的位置,使用命令查看它的值。

> xcode-select -p
/Application/Xcode.app/Contents/Developer

如果要修改套件(例如实现降级)的话,就要 xcode-select -s(需要root权限)来更新其位置

> sudo xcode-select -s /path/to/CommandLineTools

这样就可以切换CommandLineTools的版本了,我们下载前一个版本的 macOS.sdk,切过去,就能使用 -m32 编译文件了。

三、开始操作!

1、卸载 Xcode.app(可选)

因为我平时基本不用 Xcode,当初不知道为啥要下载回来,直接卸载了吧,因为默认的命令行工具指向那里面了,防止新版的SDK 卸载不干净。

2、下载安装旧版的 CommandLineTools

https://developer.apple.com/download/more/

建议下载版本为:10.13,这是带有32位链接库的最新的版本,10.14就移除掉了。
https://download.developer.apple.com/Developer_Tools/Command_Line_Tools_macOS_10.13_for_Xcode_10.1/Command_Line_Tools_macOS_10.13_for_Xcode_10.1.dmg

3、将xcode-select配置过去

默认情况下,安装好的CommandLineTools在 /Library/Developer/CommandLineTools,指定过去就好了。

四、最终成果

➜  /tmp /usr/bin/clang test.c -m32
ld: warning: The i386 architecture is deprecated for macOS (remove from the Xcode build setting: ARCHS)
➜  /tmp file a.out
a.out: Mach-O executable i386
➜  /tmp /usr/bin/clang test.cpp -m32
ld: warning: The i386 architecture is deprecated for macOS (remove from the Xcode build setting: ARCHS)
➜  /tmp file a.out
a.out: Mach-O executable i386
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值