【问题标题】:How to cross-compile clang/llvm 3.7.0 for iOS8.x on ipad mini 3?如何在 ipad mini 3 上为 iOS8.x 交叉编译 clang/llvm 3.7.0?
【发布时间】:2015-12-24 19:39:02
【问题描述】:

编辑,2015 年 10 月 24 日。 这终于奏效了:

../configure --prefix=/usr/local/lvm-cross/llvm-ios --with-default-sysroot=/usr/local/iPhoneOS8.4.sdk --host=arm-apple-darwin11 --enable-optimized --disable-assertions --disable-libedit

clang -isysroot /usr/local/iPhoneOS8.4.sdk/ -target arm64-apple-darwin11 testcpp.cpp -o testcpp

testcpp.cpp 包含:

int main()
{
    return 0;
}

现在如果我简单地修改源代码如下:

#include <iostream> // I am not even calling << operator in code, just including
int main()
{
    return 0;
}

出现以下问题:

Undefined symbols for architecture arm64:
  "std::ios_base::Init::Init()", referenced from:
      ___cxx_global_var_init in testcpp-0b9c00.o
  "std::ios_base::Init::~Init()", referenced from:
      ___cxx_global_var_init in testcpp-0b9c00.o
ld: symbol(s) not found for architecture arm64

-v 的详细说明如下:

XXXXs-iPad:~/Documents/CODING/MY/TESTS/CPP mobile$ clang -v -isysroot /usr/local/iPhoneOS8.4.sdk -target arm64-apple-darwin11 testcpp.cpp -o testcpp
clang version 3.7.0 (tags/RELEASE_370/final)
Target: arm64-apple-darwin11
Thread model: posix
 "/usr/local/llvm-ios/bin/clang" -cc1 -triple arm64-apple-ios5.0.0 -Wdeprecated-objc-isa-usage -Werror=deprecated-objc-isa-usage -Werror=implicit-function-declaration -emit-obj -mrelax-all -disable-free -disable-llvm-verifier -main-file-name testcpp.cpp -mrelocation-model pic -pic-level 2 -mthread-model posix -mdisable-fp-elim -masm-verbose -target-cpu generic -target-feature +neon -target-abi darwinpcs -target-linker-version 253.3.3 -v -dwarf-column-info -resource-dir /usr/local/llvm-ios/bin/../lib/clang/3.7.0 -isysroot /usr/local/iPhoneOS8.4.sdk -fdeprecated-macro -fdebug-compilation-dir /var/mobile/Documents/CODING/MY/TESTS/CPP -ferror-limit 19 -fmessage-length 132 -stack-protector 1 -mstackrealign -fallow-half-arguments-and-returns -fblocks -fobjc-runtime=ios-5.0.0 -fencode-extended-block-signature -fcxx-exceptions -fexceptions -fmax-type-align=16 -fdiagnostics-show-option -fcolor-diagnostics -o /var/tmp/testcpp-b164d6.o -x c++ testcpp.cpp
clang -cc1 version 3.7.0 based upon LLVM 3.7.0 default target arm-apple-darwin14.0.0
ignoring nonexistent directory "/usr/local/iPhoneOS8.4.sdk/usr/include/c++/4.2.1/arm64-apple-darwin10/"
ignoring nonexistent directory "/usr/local/iPhoneOS8.4.sdk/usr/local/include"
ignoring nonexistent directory "/usr/local/iPhoneOS8.4.sdk/Library/Frameworks"
#include "..." search starts here:
#include <...> search starts here:
 /usr/local/iPhoneOS8.4.sdk/usr/include/c++/4.2.1
 /usr/local/iPhoneOS8.4.sdk/usr/include/c++/4.2.1/backward
 /usr/local/llvm-ios/bin/../lib/clang/3.7.0/include
 /usr/local/iPhoneOS8.4.sdk/usr/include
 /usr/local/iPhoneOS8.4.sdk/System/Library/Frameworks (framework directory)
End of search list.
 "/usr/bin/ld" -demangle -dynamic -arch arm64 -iphoneos_version_min 5.0.0 -syslibroot /usr/local/iPhoneOS8.4.sdk -o testcpp /var/tmp/testcpp-b164d6.o -lSystem
Undefined symbols for architecture arm64:
  "std::ios_base::Init::Init()", referenced from:
      ___cxx_global_var_init in testcpp-b164d6.o
  "std::ios_base::Init::~Init()", referenced from:
      ___cxx_global_var_init in testcpp-b164d6.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

编辑,2015-10-21。这次我配置了:

../configure --prefix=/usr/local/lvm-cross/llvm-ios --target=arm-apple-darwin11 --host=arm-apple-darwin11 --with-default-sysroot=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS8.4.sdk --enable-optimized --disable-assertions --disable-libedit

尝试使用clang++ -v testcpp.cpp -o testcpp 再次编译会引发以下错误:

"ld" -demangle -dynamic -arch armv4t -macosx_version_min 10.10.0 -syslibroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS8.4.sdk -o testcpp /var/tmp/testcpp-bb42e7.o -lc++ -lSystem
arm-apple-darwin11-clang++: error: unable to execute command: Executable "ld" doesn't exist!
arm-apple-darwin11-clang++: error: linker command failed with exit code 1 (use -v to see invocation)

我还有这个-macosx_version_min 10.10.0 东西:坏月亮升起;令人担忧。通过 Cydia 安装 org.coolstar.cctoolsorg.coolstar.ld64 并重新编译:

"/usr/bin/ld" -demangle -dynamic -arch armv4t -macosx_version_min 10.10.0 -syslibroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS8.4.sdk -o testcpp /var/tmp/testcpp-5ae1b0.o -lc++ -lSystem
ld: library not found for -lc++
arm-apple-darwin11-clang++: error: linker command failed with exit code 1 (use -v to see invocation)

仍然是 ld: library not found for -lc++ 错误。请注意,将-isysroot=/path/to/the/iphonesdk/that/i/copied/from/my/mac/to/my/idevice 添加到编译中并没有改变我上面所说的内容。

EDIT, 2015-10-18, IV. 通过 cydia 从 BigBoss 源安装包“Darwin CC Tools”会提供ld 命令行可执行文件。再次尝试使用clang++ -v testcpp.cpp -o testcpp 编译会引发以下错误:

"/usr/bin/ld" -demangle -dynamic -arch armv4t -macosx_version_min 10.10.0 -o testcpp /var/tmp/testcpp-ddd8d4.o -lc++ -lSystem
ld: library not found for -lc++
clang++: error: linker command failed with exit code 1 (use -v to see invocation)

我猜这意味着ld找不到c++标准库文件所在的地方。如何处理?

EDIT, 2015-10-18, III. 回想起来,我认为configure 步骤一定有问题。在 iPad 上,当我尝试使用 clang++ -v testcpp.cpp -o testcpp 进行编译时,它会产生一个自然错误,指出缺少 ld,但它显示了一些奇怪的东西:"ld" -demangle -dynamic -arch armv4t -macosx_version_min 10.10.0 -o testcpp /var/tmp/testcpp-a74741.o -lc++ -lSystem -macosx_version_min 10.10.0 在这里做什么?就好像编译器正在寻找与其交叉构建的平台的 (mac os) 链接器,而不是 iOS 链接器...

EDIT, 2015-10-18, II. 其实我把整个 iOS8.4 sdk 复制到了 iPad 上,编译的时候我会-isysroot 给它。我尝试编译最简单的c++代码

int main()
{
    return 0;
}

testcpp.cppclang++ -v testcpp.cpp -o testcpp 中导致自然链接错误(因为我还没有链接器!):

clang++: error: unable to execute command: Executable "ld" doesn't exist!
clang++: error: linker command failed with exit code 1 (use -v to see invocation)

由于我不知道该选择哪种策略,所以我提出了一个问题:

Almost naked iOS8.4 --> how to get a linker?

EDIT, 2015-10-18, I. 在配置步骤传递 --disable-libedit 使我能够避开 'histedit.h' file not found 错误。然后又在ProgramTest.cpp 中出现了crt_externs.h file not found 错误,我通过评论#include 来消除它,这导致了这个错误

/Users/XXXX/Documents/CODING/src-cross/clang/llvm-3.7.0.src/unittests/Support/ProgramTest.cpp:62:18: error: 
  use of undeclared identifier '_NSGetEnviron'
char **envp = *_NSGetEnviron();
               ^

我通过简单地输入char **envp = NULL;(剧烈)来解决这个问题。 make 然后就像一个魅力,以及明显的 sudo make install。然后我scped 整个目录到我的 iPad,并尝试了/usr/local/llvm-ios/bin/clang,它告诉我...clang: error: no input files。成功。 ;-) 现在,由于安装是赤裸裸的,我需要找到所有标准库(iostream 等)...

编辑,2015 年 10 月 17 日。 在 Thomas 建议之后,我尝试了这个(只是使用 8.4 而不是 8.3 sdk,因为我越狱的 ipad mini 3 wifi 是在 iOS 8.4 下):

curl -O http://llvm.org/releases/3.7.0/llvm-3.7.0.src.tar.xz
tar -Jxf llvm-3.7.0.src.tar.xz
cd llvm-3.7.0.src/tools/
curl -O http://llvm.org/releases/3.7.0/cfe-3.7.0.src.tar.xz
tar -Jxf cfe-3.7.0.src.tar.xz
mv cfe-3.7.0.src clang
cd ..
export CC="clang -arch arm64 -mios-version-min=8.4 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS8.4.sdk"
export CXX="clang++ -arch arm64 -mios-version-min=8.4 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS8.4.sdk"
mkdir build && cd build

为了避免以下错误:

/Users/XXX/Documents/CODING/src-cross/clang/llvm-3.7.0.src/utils/unittest/googletest/src/gtest-death-test.cc:40:12: fatal error: 'crt_externs.h' file not found
#  include <crt_externs.h>
           ^

Thomas 在帖子 How to cross-compile clang/llvm for iOS? 中警告我们,我去了 /Users/XXX/Documents/CODING/src-cross/clang/llvm-3.7.0.src/utils/unittest/googletest/src/gtest-death-test.cc 并评论了 #include &lt;crt_externs.h&gt;。然后我在

中找到了char** GetEnviron()函数
#  if GTEST_OS_MAC
inline char** GetEnviron() {
  // When Google Test is built as a framework on MacOS X, the environ variable
  // is unavailable. Apple's documentation (man environ) recommends using
  // _NSGetEnviron() instead.
  return *_NSGetEnviron();
}

并将原来的return *_NSGetEnviron(); 替换为return NULL;。然后我继续使用configureunsetmake VERBOSE=1 -j

../configure --prefix=/usr/local/XXX-cross/llvm-ios --host=arm-apple-darwin11 --enable-optimized --disable-assertions
unset CC CXX
make VERBOSE=1 -j

后者触发了以下错误:

/Users/XXXX/Documents/CODING/src-cross/clang/llvm-3.7.0.src/lib/LineEditor/LineEditor.cpp:17:10: fatal error: 'histedit.h' file not found
#include <histedit.h>
         ^

我不知道如何解决......


最初的问题。我正在尝试在 ipad mini 3 上为 iOS8.x 交叉编译 clang/llvm 3.7.0,借助以下工具:

How to cross-compile clang/llvm for iOS?

我已经试过了:

curl -O http://llvm.org/releases/3.7.0/llvm-3.7.0.src.tar.xz
tar -Jxf llvm-3.7.0.src.tar.xz
cd llvm-3.7.0.src/tools/
curl -O http://llvm.org/releases/3.7/clang-3.7.src.tar.gz
tar -Jxf cfe-3.7.0.src.tar.xz
mv cfe-3.7.0.src clang
cd ..
export CC="clang -arch armv8a -mios-version-min=8.3 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS8.3.sdk"
export CXX="clang++ -arch armv8a -mios-version-min=8.3 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS8.3.sdk"
mkdir build && cd build
../configure --prefix=/usr/local/XXX-cross/llvm-ios --host=armv8a-apple-darwin-eabi --enable-optimized --disable-assertions

没有成功,有

error: invalid arch name '-arch armv8a'

对于我尝试过的与 iPad mini 3 相关的所有archhost,我都遇到了这种错误,为此我找到了herethere 的信息。

当我尝试为我的 iPad mini 3 构建 gcc 时,我遇到了同样的问题,我现在的印象是,无论我试图为这个目标“交叉构建”什么编译器,正确的 @不支持 987654388@ 和 arch 选项。

我错了?我有办法传递处理通用/未知 archhost 的其他选项,如果有合适的其他选项,我的 iPad mini 3 上会有可用的 llvm-clang 吗?

【问题讨论】:

  • 检查你的SDK是否自带libc++.dylib,对于-mmacosx-version-min的问题,试试clang -isysroot &lt;...&gt; -target arm64-apple-darwin11
  • 我的 SDK 文件夹中有 libc++.dylib /usr/local/llvm-ios/iPhoneOS8.4.sdk/usr/lib/libc++.dylib... 将 -isysroot &lt;...&gt; 添加到编译参数会引发 ld: building for MacOSX, but linking against dylib built for iOS Simulator file '/usr/local/llvm-ios/iPhoneOS8.4.sdk/usr/lib/libSystem.dylib' for architecture armv4t。 (精度:我是在 iDevice 上做这个,而不是交叉做。) 完整输出:gist.github.com/MisesEnForce/55d8a3f6e319e7ca4901
  • 添加-target arm64-apple-darwin11
  • 哦,好的,好电话,我忘记了-target 部分,今晚会再试一次。不过,在为 iDevice 编译时必须在 iDevice 上指定它很奇怪。
  • 也许您应该尝试 --target=TARGET--with-default-sysroot llvm/clang 配置选项 - 请参阅 ./configure --help

标签: ios gcc clang llvm cross-compiling


【解决方案1】:

这是-arch arm64 不是-arch armv8a,并将--host=armv8a-apple-darwin-eabi 更改为--host=arm-apple-darwin11

另外,-isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS8.3.sdk 仅在您使用 Mac 为 iOS 进行交叉编译时才有意义。

【讨论】:

  • 我确实为此使用了 mac。尝试了您的建议并出现此错误:/Users/XXX/Documents/CODING/src-cross/clang/llvm-3.7.0.src/utils/unittest/googletest/src/gtest-death-test.cc:40:12: fatal error:'crt_externs.h' file not found
  • @user10000100_u:阅读我的其他答案@stackoverflow.com/questions/23946851/… 了解原因(您甚至已经链接到它!)。要么为_NSGetEnviron() 提供原型,要么删除函数调用。
  • 我也有 clang/llvm-3.7.0.src/lib/LineEditor/LineEditor.cpp:17:10: 致命错误: 'histedit.h' 文件未找到并评论它的包含不会'不会像 _NSGetEnviron() 那样导致简单的事情
  • (我返回的是NULL而不是_NSGetEnviron()
  • 我编辑了我的问题,以精确说明我尝试过的内容(考虑了您的所有评论)并显示我遇到的新错误。 (我所指的链接中没有提到。)
猜你喜欢
  • 2014-07-19
  • 2020-08-29
  • 2014-01-10
  • 2014-03-10
  • 2019-03-09
  • 2020-01-19
  • 2020-10-05
  • 1970-01-01
  • 2012-02-27
相关资源
最近更新 更多