如何在ipad mini 3上交叉编译iOS8.x的clang / llvm 3.7.0?

时间:2015-09-27 12:57:32

标签: ios gcc clang llvm cross-compiling

编辑,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++标准库文件所在的位置。怎么处理这个?

编辑,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.cpp中带有clang++ -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?

编辑,2015-10-18,我。在配置步骤中传递--disable-libedit,可以避免'histedit.h' file not found错误。然后再次在crt_externs.h file not found中发现ProgramTest.cpp错误,我通过评论#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显而易见。然后我scp将整个目录编辑到我的iPad上,然后尝试/usr/local/llvm-ios/bin/clang告诉我...... clang: error: no input files。成功。 ;-)现在,由于安装是裸的,我需要找到所有标准库(iostream等)......

编辑,2015-10-17。在托马斯建议之后我尝试了这个(仅使用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>
           ^
托马斯在帖子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 <crt_externs.h>发表了评论。然后我在

中找到了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'

我的所有archhost我尝试过与我的iPad mini 3相关的错误,我找到了这个错误信息here和{ {3}}

当我尝试为我的iPad mini 3构建gcc时,我遇到了同样的问题,我的印象是,目前,无论我试图为这个目标“交叉构建”的编译器,都是正确的{ {1}}&amp;

我错了?我有办法通过其他选项处理泛型/未知host的&amp; arch,有合适的其他选择,会在我的iPad mini 3上为我提供可行的llvm-clang吗?

1 个答案:

答案 0 :(得分:1)

-arch arm64而非-arch armv8a,并将--host=armv8a-apple-darwin-eabi更改为--host=arm-apple-darwin11

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