[llvm-dev] Trying to compile LLVM/Clang for iOS iPhoneSimulator gives errors

Igor Gomon via llvm-dev llvm-dev at lists.llvm.org
Wed Apr 15 15:45:24 PDT 2020

Thank you Jacob for your answer. It is quite helpful. 
Sorry for not responding sooner - I wasn't getting messages from llvm-dev for awhile for some reason and had to re-subscribe from a different e-mail address.

So I followed the link at the bottom	of your response and I am now using the following command to cross-compile for iOS:
cmake -S . -B build_iOS_make -G "Unix Makefiles"  -DCMAKE_SYSTEM_NAME=iOS "-DCMAKE_OSX_ARCHITECTURES=x86_64" -DLLVM_ENABLE_PROJECTS=clang -DCMAKE_INSTALL_PREFIX=`pwd`/_install -DCMAKE_XCODE_ATTRIBUTE_ONLY_ACTIVE_ARCH=NO -DCMAKE_IOS_INSTALL_COMBINED=YES -DCMAKE_OSX_SYSROOT="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator13.4.sdk"

And with that I was able to compile some 61% of LLVM. 
Now I am stuck here:

[ 61%] Built target yaml-bench
[ 61%] Built target LTO_exports
[ 61%] Linking CXX shared library ../../lib/libLTO.dylib
ld: unknown option: -z
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [lib/libLTO.dylib] Error 1
make[1]: *** [tools/lto/CMakeFiles/LTO.dir/all] Error 2
make: *** [all] Error 2

I am now going through the CMake scripts trying to figure out where that option is set and how to remove it.
Honestly, I am not even sure what that options means. I tried ignoring libLTO target but it had snowballing effect as that target is referenced in a number of other places it seems.

As for your remark about not being able to invoke the “fork” system call: my hope was to interpret C++ code on the target platform - the way lli tool does or JIT-compiling it when possible.
I am not sure about that, though - so wanted to give that a try to see how that goes.

Best Regards,
Igor Gomon

Jacob Carlborg via llvm-dev llvm-dev at lists.llvm.org  <mailto:llvm-dev%40lists.llvm.org?Subject=Re%3A%20%5Bllvm-dev%5D%20Trying%20to%20compile%20LLVM/Clang%20for%20iOS%20iPhoneSimulator%0A%09gives%20errors&In-Reply-To=%3Cr5vbiv%24c7s%241%40ciao.gmane.io%3E>Tue Mar 31 05:03:43 PDT 2020

Previous message: [llvm-dev] Trying to compile LLVM/Clang for iOS iPhoneSimulator gives errors <http://lists.llvm.org/pipermail/llvm-dev/2020-March/140488.html>
Next message: [llvm-dev] llvm-lit and cmake and out-of-tree builds. <http://lists.llvm.org/pipermail/llvm-dev/2020-March/140496.html>
Messages sorted by: [ date ] <http://lists.llvm.org/pipermail/llvm-dev/2020-March/date.html#140513> [ thread ] <http://lists.llvm.org/pipermail/llvm-dev/2020-March/thread.html#140513> [ subject ] <http://lists.llvm.org/pipermail/llvm-dev/2020-March/subject.html#140513> [ author ] <http://lists.llvm.org/pipermail/llvm-dev/2020-March/author.html#140513>
On 2020-03-30 23:37, Igor Gomon via llvm-dev wrote:

> I am trying to compile LLVM/Clang(10.0) for iOS Simulator (SDK 13.4)
The way code is compiled for iOS (simulator or native device) is to 
cross-compile it.

As far as I know, it's not possible to run a compiler on the simulator 
or device. You're not allowed to invoke the "fork" system call, that 
means you cannot create a new process. That means, if you do have a 
compiler for iOS, there's no way to run it.

BTW, the proper way to cross-compile for iOS using cmake is to set the 
following cmake variables:

CMAKE_OSX_ARCHITECTURES=arm64 # architecture
CMAKE_OSX_DEPLOYMENT_TARGET=12.0 # minimum deployment target

The above are examples for targeting the native device. Not sure of the 
exact values for the simulator.

For more information, see: 
https://cmake.org/cmake/help/v3.14/manual/cmake-toolchains.7.html#cross-compiling-for-ios-tvos-or-watchos <https://cmake.org/cmake/help/v3.14/manual/cmake-toolchains.7.html#cross-compiling-for-ios-tvos-or-watchos>

/Jacob Carlborg

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20200415/f49b93f6/attachment.html>

More information about the llvm-dev mailing list