linux - How to link mach-o format object files on linux?
问题描述
I have been attempting to link a MACHO formatted object file on Linux, but I have failed miserably. So far, I have created the object file by running:
nasm -fmacho -o machoh.o hello.o
I have tried linking using:
clang --target=x86_64-apple-darwin machoh.o
but that failed. I have attempted using GCC, LD, and other linkers but I have still failed miserably. Are there any ideas on how I could solve my problem?
Thank you very much.
解决方案
最容易获得的解决方案是lld
LLVM 链接器。
lld 不附带 clang,而是一个单独的包。
sudo apt install lld
如果您安装了非默认的 clang 版本(例如
clang-12
显式),那么您应该为 lld 使用相同的版本(即lld-12
)。从某个地方获取 MacOS SDK。这个 GitHub 存储库将它们存档。
如果您对使用上述内容感到不舒服,那么在没有 Mac 的情况下获得它的“合法”方式是:
- 创建 Apple ID
- 转到https://developer.apple.com/download/all/
- 下载“Xcode <版本>的命令行工具”
- 挂载或提取 dmg
- 提取 XAR 包
- 对于里面的每个“.pkg”文件夹,运行
pbzx <Payload | cpio -i
- 找到
Library/Developer/CommandLineTools/SDKs/MacOSX.sdk
里面。
将上述两者都喂给叮当声:
clang --target=x86_64-apple-darwin -fuse-ld=lld --sysroot=path/to/MacOSX.sdk machoh.o
推荐阅读
- angular - 加载后如何保存数据以供将来在 angular9 应用程序中使用?
- python - python shell子进程无需等待?
- r - 有没有办法将 3d 数组的 2d 矩阵乘以 R 中的标量?
- azure - 以下团队项目收集已停止...启动收集然后重试
- python - 中断脚本会删除 Jupyter Notebook 中的进度吗?
- javascript - JavaScript 如何比较相同的 DOM 元素?
- cypress - 赛普拉斯中受 CSRF 保护的登录问题
- flutter - 设置从 Shared Preferences 获得的初始值到控制器
- python - 删除矩形(吃苹果)
- linux - 脚本不会在 crontab 上执行