0

EDIT, 2015-10-24. This finally worked :

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

with

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

where testcpp.cpp contains :

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;
}

the following problem appears :

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

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. This time I configured with :

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

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)

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)

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

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. 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...

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;
}

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 :

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

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();
               ^

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

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

To avoid the following error :

/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 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();
}

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

The latter triggered the following error :

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


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 :

How to cross-compile clang/llvm for iOS?

I have tried this :

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

without success, having the

error: invalid arch name '-arch armv8a'

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.

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.

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 ?

Community
  • 1
  • 1
Olórin
  • 3,367
  • 2
  • 22
  • 42
  • Check if your SDK comes with `libc++.dylib`, for the `-mmacosx-version-min` issue, try `clang -isysroot <...> -target arm64-apple-darwin11`. – Thomas Oct 19 '15 at 10:19
  • I do have `libc++.dylib` in my SDK folder `/usr/local/llvm-ios/iPhoneOS8.4.sdk/usr/lib/libc++.dylib`... Adding `-isysroot <...>` to compilation parameters provoked `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`. (Precision : I am doing this on the iDevice, not cross-doing it.) Complete output in the gist : https://gist.github.com/MisesEnForce/55d8a3f6e319e7ca4901 – Olórin Oct 19 '15 at 17:52
  • Add `-target arm64-apple-darwin11` nevertheless. – Thomas Oct 20 '15 at 07:35
  • Oh ok, good call, I forgot the `-target` piece, will trying again tonight. It is curious to have to specify it on iDevice while compiling for iDevice though. – Olórin Oct 20 '15 at 07:44
  • Maybe you should try the `--target=TARGET` and `--with-default-sysroot` llvm/clang configure options - see `./configure --help`. – Thomas Oct 21 '15 at 17:01
  • "`--host=HOST` : cross-compile to build programs to run on HOST [BUILD]" and "`--target=TARGET` : configure for building compilers for TARGET [HOST]", so, if I understand well : the `--host` option tells that the compiler I will have configured will compile programs that will run on HOST and the `--target` options tells that the compiler I will have configured will run on TARGET. So, I am already rightly passing `--host=arm-apple-darwin11`, but I shoul also `--target=arm-apple-darwin11`, and not passing it makes probably `configure` passing `--target=x86_64-apple-darwin14.5.0`, which ... – Olórin Oct 21 '15 at 18:37
  • ... probably explains the `-macosx_version_min 10.10.0` appearing in the verbose version of the `ld` error triggered by compilation : the compiler looks for the TARGET linker, and as target is probably `x86_64-apple-darwin14.5.0`, problem. – Olórin Oct 21 '15 at 18:40
  • I don't get the `--with-default-sysroot` though. Should I put for it the path to the iOS8.4 sdk folder on my mac or ? I don't think so, as it seems to be an option for the system on which the configure is executed (mac) : "Add `--sysroot=` to all compiler invocations" – Olórin Oct 21 '15 at 18:42
  • The path to the SDK on the iOS device, for `--target` pass `arm64-apple-darwin11` to the configure script. – Thomas Oct 23 '15 at 10:03
  • So `../configure --prefix=/usr/local/lvm-cross/llvm-ios --host=arm-apple-darwin11 --target=arm64-apple-darwin11 --with-default-sysroot=/usr/local/iPhoneOS8.4.sdk —enable-optimized --disable-assertions --disable-libedit` where `/usr/local/iPhoneOS8.4.sdk` is a path on my iPad to the folder `iPhoneOS8.4.sdk` copied from my mac. Correct ? Question : why the `64` in the `--target` but not in the `--host` ? Or should I add it also in the `--host` ? – Olórin Oct 23 '15 at 16:48
  • Yes. Configure scripts usually don't like `arm64`, passing arm to `--host` should work too. – Thomas Oct 23 '15 at 17:21
  • `checking host system type... Invalid configuration `arm64-apple-darwin11': machine `arm64-apple' not recognized`... – Olórin Oct 23 '15 at 20:31
  • Then use my previous method via a wrapper. – Thomas Oct 24 '15 at 11:32
  • Hum, what do you mean, "via a wrapper" ? – Olórin Oct 24 '15 at 11:32
  • https://stackoverflow.com/questions/23946851/how-to-cross-compile-clang-llvm-for-ios#comment54200976_23950039 – Thomas Oct 24 '15 at 12:32
  • @Thomas I still don't understand what the wrapper method is. In this link you only mentioned wrapping for `--isysroot'. My problem here is `arm64-apple' not recognized`. What should be wrapped, and by what ? – Olórin Oct 24 '15 at 12:36
  • Please excuse me, but I am slowly getting a little bit angry... Do you even read what I am writing? "Configure scripts usually don't like arm64". On the iOS device, use **exactly** this: `clang -isysroot -target arm64-apple-darwin11 `. ***This does indeed work***. I did this myself several times. For easyness sake you can put this into a shell wrapper. Google for it. – Thomas Oct 24 '15 at 14:36
  • I do read, and you wrote "The path to the SDK on the iOS device, `for --target` pass `arm64-apple-darwin11` to the configure script". "To the configure script", you see ?. So I do read well. And I could in turn get a little bit angry, but I don't. As there's no need. Anyway now it works, no linking problems anymore, thx. But `#include ` triggers `Undefined symbols for architecture arm64: "std::ios_base::Init::Init()"` – Olórin Oct 24 '15 at 16:35
  • The output you posted was for `--host`, not `--target`. I haven't had in mind `--target` also triggers that error unnecessarily; despite that, I posted a working solution 4 days ago. Anyway, for `Undefined symbols for architecture arm64: "std::ios_base::Init::Init()` add `-v` and post the output, otherwise I can't judge what's going on. – Thomas Oct 24 '15 at 16:55
  • @Thomas Updated with `clang -v <...>` output. – Olórin Oct 24 '15 at 17:06
  • Invoke `clang++` instead of `clang` for C++ programs. – Thomas Oct 24 '15 at 17:07
  • @Thomas Thx a lot, indeed – Olórin Oct 27 '15 at 21:49

1 Answers1

1

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

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.

Thomas
  • 3,074
  • 1
  • 25
  • 39
  • I am indeed using a mac for this. Tried what you suggested and had this error : `/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` – Olórin Oct 16 '15 at 20:11
  • @user10000100_u: Read my other answer @ https://stackoverflow.com/questions/23946851/how-to-cross-compile-clang-llvm-for-ios to see why (you have even linked to it!). Either provide a prototype for `_NSGetEnviron()` or remove the function calls. – Thomas Oct 16 '15 at 20:27
  • I also have clang/llvm-3.7.0.src/lib/LineEditor/LineEditor.cpp:17:10: fatal error: 'histedit.h' file not found And commenting its include won't lead to easy stuff as for _NSGetEnviron() – Olórin Oct 16 '15 at 21:37
  • (I am returning `NULL` instead of `_NSGetEnviron()`) – Olórin Oct 16 '15 at 21:51
  • I edit my question to precise what I tried (took in account all you comment) and show a new error I have. (One not mentionned in the link I was referring to.) – Olórin Oct 17 '15 at 11:13
  • With Xcode11, the host name ended up being `arm` for me. Your suggested host name does not compile. However, even with `arm`, the slice in the lipo output is actually x86_64. I'm still investigating why. – kakyo Oct 09 '19 at 09:57
  • @kakyo: That's weird. Maybe try to add `-target arm-apple-darwin` – Thomas Oct 10 '19 at 10:38