【问题标题】:Clang compiling for iOS (arm64) with -shared LDFLAG - Exec format error使用 -shared LDFLAG 为 iOS (arm64) 编译 Clang - Exec 格式错误
【发布时间】:2021-11-24 04:08:55
【问题描述】:

新手提醒,如果这个问题重复,请提前抱歉(在其他地方没有找到答案)!

我在 macOS 机器 (x86_64) 上构建 iOS (arm64) 的简单 hello 二进制文件时遇到了问题。

问题是,当我使用共享框架(即“-shared -framework CoreMedia”或其他框架)添加 LDFLAGS 来构建我的二进制文件时,它编译得很好,但是当它在设备上执行时,我得到 Exec format error

iPhone:/tmp root# ./hello 
-sh: ./hello: cannot execute binary file: Exec format error

构建没有 -shared 标志它按预期运行:

iPhone:/tmp root# ./hello 
Hello

有人可以向我解释为什么这个标志会导致二进制执行错误吗?它是否与我正在构建的平台而不是目标设备有关?

我应该在 arm64 平台上构建以使 -shared 标志正常工作吗?

以防万一,构建脚本是:

export CLANG_BIN=`xcrun --sdk iphoneos --find clang`
export CLANGXX_BIN=`xcrun --sdk iphoneos --find clang++`
export SDK=`xcrun --sdk iphoneos --show-sdk-path`

export CFLAGS="-fno-builtin -fno-stack-protector -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/ -fno-stack-protector -Wno-builtin-requires-header -fno-stack-check"
#export LDFLAGS="-shared -framework CoreMedia" # <- exec error when this added to compile
export LDFLAGS="-framework CoreMedia" # <- with just this, bin executes fine

export CXX="$CLANGXX_BIN $CFLAGS -isysroot $SDK"

$CXX -arch arm64 -o hello hello.c $LDFLAGS -Wall -Wconversion

【问题讨论】:

    标签: c++ ios clang clang++ jailbreak


    【解决方案1】:

    -shared 表示您正在构建一个共享库。
    您不能运行共享库。

    【讨论】:

    • 感谢您的回答!我认为 -shared 标志与链接框架有关,而不是与整个编译输出有关
    猜你喜欢
    • 2018-12-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-08-20
    • 1970-01-01
    • 2014-06-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多