本文介绍了如何在ipad mini 3上交叉编译iOS8.x的clang/llvm 3.7.0?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

编辑,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;
}

现在,如果我将源代码修改如下:

Now if I modfified the source code simply as follows :

#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的详细程度给出了这一点:

Verbosity with -v gives this :

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)

EDIT,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进行编译会引发以下错误:

Trying to compile with clang++ -v testcpp.cpp -o testcpp again throws then the following error :

"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)

我仍然有这个东西[c3]:不良的月亮升起;令人担忧.通过Cydia安装org.coolstar.cctoolsorg.coolstar.ld64并重新编译,得到了:

I still have this -macosx_version_min 10.10.0 stuff : bad moon rising ; worrying. Installing org.coolstar.cctools and org.coolstar.ld64 via Cydia and recompiling gave :

"/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并不会改变我上面所说的内容.

still the ld: library not found for -lc++ error. Note that adding -isysroot=/path/to/the/iphonesdk/that/i/copied/from/my/mac/to/my/idevice to the compilation did not change a single thing to what I have stated above.

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

EDIT, 2015-10-18, IV. Installing the package "Darwin CC Tools" from the BigBoss source via cydia furnishes the ld command line executable. Trying to compile with clang++ -v testcpp.cpp -o testcpp again throws then the following error :

"/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++标准库文件所在的位置.该如何处理?

I guess that it means that ld can't find the place where the c++ standard library files are. How to deal with this ?

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, III. Retrospectively I think there must be an issue with the configure step. On the iPad when I try to compile with clang++ -v testcpp.cpp -o testcpp it produce a natural error saying that ld is missing, but it shows something strange : "ld" -demangle -dynamic -arch armv4t -macosx_version_min 10.10.0 -o testcpp /var/tmp/testcpp-a74741.o -lc++ -lSystem What does this -macosx_version_min 10.10.0 do here ? It is as if the compiler was looking for the (mac os) linker of the plateform it was cross-build with instead of the iOS one...

编辑,2015-10-18,II.实际上,我将整个iOS8.4 sdk复制到了iPad,在编译过程中将-isysroot复制到iPad.我试图编译最简单的C ++代码

EDIT, 2015-10-18, II. Actually I copied the whole iOS8.4 sdk to the iPad, and I will -isysroot to it during compilation. I tried to compile the simplest c++ code

int main()
{
    return 0;
}

testcpp.cpp中的

clang++ -v testcpp.cpp -o testcpp一起导致了自然的链接错误(因为我还没有链接器!):

in testcpp.cpp with clang++ -v testcpp.cpp -o testcpp which led to a natural linking error (as I don't have a linker yet !) :

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)

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

As I don't know which strategy to opt for, I created a question :

几乎是裸露的iOS8.4 ->如何获得链接器?

编辑,2015-10-18,我.在配置步骤中通过--disable-libedit可以避免'histedit.h' file not found错误.然后又出现了ProgramTest.cpp中的crt_externs.h file not found错误,我通过注释#include消除了该错误,从而导致了此错误

EDIT, 2015-10-18, I. Passing --disable-libedit at the configure step allowed me to elude the 'histedit.h' file not found error. Had then again a crt_externs.h file not found error in ProgramTest.cpp that I get rid of by commenting the #include, which led to this error

/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等)...

that I fixed by simply putting char **envp = NULL; (drastic). The make went then like a charm, as well as obvioulsy the sudo make install. Then I scped the whole directory to my iPad, and tried /usr/local/llvm-ios/bin/clang which told me... clang: error: no input files. Success. ;-) Now, as the install is naked, I need to find all standard libraries (iostream etc)...

编辑,2015-10-17.在Thomas提出建议后,我尝试了此操作(因为我越狱的ipad mini 3 wifi在iOS 8.4下使用了8.4而不是8.3 sdk):

EDIT, 2015-10-17. After Thomas suggested it I tried this (just used 8.4 instead of 8.3 sdk as my jailbroken ipad mini 3 wifi is under 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在帖子中警告我们/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()函数

Thomas warns us about in the post How to cross-compile clang/llvm for iOS?, I went to /Users/XXX/Documents/CODING/src-cross/clang/llvm-3.7.0.src/utils/unittest/googletest/src/gtest-death-test.cc and commented the #include <crt_externs.h>. Then I found the char** GetEnviron() function in

#  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:

and replaced the orignal return *_NSGetEnviron(); with return NULL;. Then I continued with the configure, the unset and the make 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>
         ^

我不知道该怎么解决...

which I don't know how to tackle...

初始问题.我试图借助以下帮助在ipad mini 3上交叉编译iOS8.x的clang/llvm 3.7.0:

Initial question. I am trying to cross-compile clang/llvm 3.7.0 for iOS8.x on ipad mini 3, with the help of the following :

如何为iOS交叉编译clang/llvm? a>

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都存在此类错误,我发现了相关信息此处那里.

And I had this kind of error for all arch's and host's I've tried related to my iPad mini 3, for which I found infos here and there.

当我尝试为iPad mini 3构建gcc时,我遇到了同样的问题,并且给人的印象是,目前,无论我要为该目标交叉构建"的任何编译器,正确的host& arch选项不受支持.

I had the same kind of problem when I tried to build gcc for my iPad mini 3, and I have the impression that at the moment, whatever compiler I am trying to "cross-build" for this target, the correct host & arch options are not supported.

我错了?我有一种方法可以传递处理通用/未知arch的&的其他选项. host,还有其他合适的选择,会给我iPad mini 3上可行的llvm-clang吗?

I am wrong ? I there a way to pass other options dealing with generic/unknown arch's & host's, that with suitable other options, would give me workable llvm-clang on my iPad mini 3 ?

推荐答案

它是-arch arm64而不是-arch armv8a,然后将--host=armv8a-apple-darwin-eabi更改为--host=arm-apple-darwin11.

It's -arch arm64 not -arch armv8a, and change --host=armv8a-apple-darwin-eabi to --host=arm-apple-darwin11.

而且-isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS8.3.sdk仅在使用Mac交叉编译iOS版本时才有意义.

Also -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS8.3.sdk only makes sense when you are using a Mac to cross compile for iOS.

这篇关于如何在ipad mini 3上交叉编译iOS8.x的clang/llvm 3.7.0?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 08:57