<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">I hope this is on topic for this list, since I expect that someone here must already have done this successfully, while I am still foundering around.<div class=""><br class=""></div><div class="">What I want to achieve is to build LLVM (and, in particular, clang/clang++ with OpenMP support) to run on and target the Apple M1 ARM processor running MacOS Big Sur. (I have a new Mac Mini :-)).</div><div class="">Ideally, it would be nice to be able to build a dual target fat-binary in which the X86_64 component compiled for X86_64 by default, and the Aarch64 component compiled or Aarch64 by default (this is what the Apple compiler in Xcode does…), however just being able to build an Aarch64 compiler that worked would be ahead of what I have managed to achieve.</div><div class=""><br class=""></div><div class="">My best attempt is configured using this script from a build directory inside the top-level llvm checkout.</div><div class="">The compilers found are those from Xcode.</div><div class=""><br class=""></div><div class=""><div class=""><font face="Courier New" class=""># Xcode, Ninja</font></div><div class=""><font face="Courier New" class="">BUILD_SYSTEM=Ninja</font></div><div class=""><font face="Courier New" class="">BUILD_TAG=ninja</font></div><div class=""><font face="Courier New" class=""><br class=""></font></div><div class=""><font face="Courier New" class="">cmake ../llvm \</font></div><div class=""><font face="Courier New" class="">      -G$BUILD_SYSTEM -B ${BUILD_TAG}_build \</font></div><div class=""><font face="Courier New" class="">      -DCMAKE_OSX_ARCHITECTURES='arm64' \</font></div><div class=""><font face="Courier New" class="">      -DCMAKE_C_COMPILER=`which clang` \</font></div><div class=""><font face="Courier New" class="">      -DCMAKE_CXX_COMPILER=`which clang++` \</font></div><div class=""><font face="Courier New" class="">      -DCMAKE_BUILD_TYPE=Release \</font></div><div class=""><font face="Courier New" class="">      -DCMAKE_BUILD_WITH_INSTALL_RPATH=1 \</font></div><div class=""><font face="Courier New" class="">      -DCMAKE_INSTALL_PREFIX=$HOME/software/clang-12.0.0/arm64 \</font></div><div class=""><font face="Courier New" class="">      -DLLVM_LOCAL_RPATH=$HOME/software/clang-12.0.0/arm64/lib \</font></div><div class=""><font face="Courier New" class="">      -DLLVM_ENABLE_WERROR=FALSE \</font></div><div class=""><font face="Courier New" class="">      -DLLVM_TARGETS_TO_BUILD='AArch64' \</font></div><div class=""><font face="Courier New" class="">      -DLLVM_DEFAULT_TARGET_TRIPLE='aarch64-apple-darwin20.1.0' \</font></div><div class=""><font face="Courier New" class="">      -DDEFAULT_SYSROOT="$(xcrun --show-sdk-path)" \</font></div><div class=""><font face="Courier New" class="">      -DLLVM_ENABLE_PROJECTS='clang;openmp;polly;clang-tools-extra;libcxx;libcxxabi' </font></div><div class=""><br class=""></div><div class="">Configured like that I can build a compiler, OpenMP runtime and so on. </div><div class=""><br class=""></div><div class="">However…</div><div class="">1)  when linking it does not add<font face="Courier New" class=""> -L$HOME/software/clang-12.0.0/arm64/lib </font><font face="HelveticaNeue" class="">to the linker command, so it fails to link OpenMP codes which require l</font><font face="Courier New" class="">ibomp.dylib</font><font face="HelveticaNeue" class="">, since it doesn't find it. (See below:  you can see that it did add the local, LLVM, include directory, so was able to find <omp.h>).</font></div><div class=""><font face="HelveticaNeue" class="">2) If I fake that by explicitly adding the -L command, then it links OK, but fails to find libomp.dylib at runtime, even though it does look in some “brew” related places (despite not having anything like that in any envirables).</font></div><div class=""><div class=""><font face="Courier New" class="">$ ./a.out</font></div><div class=""><font face="Courier New" class="">dyld: Library not loaded: @rpath/libomp.dylib</font></div><div class=""><font face="Courier New" class="">  Referenced from: /Users/jcownie/tmp/./a.out</font></div><div class=""><font face="Courier New" class="">  Reason: no suitable image found.  Did find:</font></div><div class=""><font face="Courier New" class=""><span class="Apple-tab-span" style="white-space:pre">     </span>/usr/local/lib/libomp.dylib: mach-o, but wrong architecture</font></div><div class=""><font face="Courier New" class=""><span class="Apple-tab-span" style="white-space:pre">      </span>/usr/local/Cellar/libomp/11.0.0/lib/libomp.dylib: mach-o, but wrong architecture</font></div><div class=""><font face="Courier New" class="">Abort trap: 6</font></div></div><div class=""><font face="HelveticaNeue" class=""><br class=""></font></div><div class=""><font face="HelveticaNeue" class="">Any help gratefully received!</font></div><div class=""><font face="HelveticaNeue" class=""><br class=""></font></div><div class=""><font face="HelveticaNeue" class=""> (I have a StackOverflow question at <a href="https://stackoverflow.com/questions/65293299/how-to-build-llvm-clang-clang-for-apple-m1" class="">https://stackoverflow.com/questions/65293299/how-to-build-llvm-clang-clang-for-apple-m1</a> which contains similar information to that I have inlined here; if you would rather answer there, that’s fine, but don't feel bound to. If i get an answer here i’ll update that myself so others can see it.)</font></div><div class=""><font face="HelveticaNeue" class=""><br class=""></font></div><div class=""><font face="HelveticaNeue" class="">Thanks<br class=""></font><div class="">
<div style="color: rgb(0, 0, 0); letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><div class=""><br class=""></div><div class="">-- Jim<br class="">James Cownie <<a href="mailto:jcownie@gmail.com" class="">jcownie@gmail.com</a>><br class="">Mob: +44 780 637 7146<br class=""><br class="">Compilation, and linkage failure.<br class=""><div class=""><font face="Courier New" class="">$ ~/software/clang-12.0.0/arm64/bin/clang -v -fopenmp hello_omp.c</font></div><div class=""><font face="Courier New" class="">clang version 12.0.0 (<a href="https://github.com/llvm/llvm-project.git" class="">https://github.com/llvm/llvm-project.git</a> 975b64b29375cdfb3672fedee4216c6512672fbf)</font></div><div class=""><font face="Courier New" class="">Target: aarch64-apple-darwin20.2.0</font></div><div class=""><font face="Courier New" class="">Thread model: posix</font></div><div class=""><font face="Courier New" class="">InstalledDir: /Users/jcownie/software/clang-12.0.0/arm64/bin</font></div><div class=""><font face="Courier New" class=""> "/Users/jcownie/software/clang-12.0.0/arm64/bin/clang-12" -cc1 -triple arm64-apple-macosx11.0.0 -Wundef-prefix=TARGET_OS_ -Werror=undef-prefix -Wdeprecated-objc-isa-usage -Werror=deprecated-objc-isa-usage -emit-obj -mrelax-all --mrelax-relocations -disable-free -disable-llvm-verifier -discard-value-names -main-file-name hello_omp.c -mrelocation-model pic -pic-level 2 -mframe-pointer=non-leaf -fno-rounding-math -munwind-tables -fcompatibility-qualified-id-block-type-checking -fvisibility-inlines-hidden-static-local-var -target-cpu apple-a12 -target-feature +v8.3a -target-feature +fp-armv8 -target-feature +neon -target-feature +crc -target-feature +crypto -target-feature +fullfp16 -target-feature +ras -target-feature +lse -target-feature +rdm -target-feature +rcpc -target-feature +zcm -target-feature +zcz -target-feature +sha2 -target-feature +aes -target-abi darwinpcs -fallow-half-arguments-and-returns -debugger-tuning=lldb -target-linker-version 609.8 -v -resource-dir /Users/jcownie/software/clang-12.0.0/arm64/lib/clang/12.0.0 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk -internal-isystem /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/local/include -internal-isystem /Users/jcownie/software/clang-12.0.0/arm64/lib/clang/12.0.0/include -internal-externc-isystem /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include -fdebug-compilation-dir /Users/jcownie/tmp -ferror-limit 19 -fmessage-length=167 -fopenmp -fopenmp-cuda-parallel-target-regions -stack-protector 1 -fblocks -fencode-extended-block-signature -fregister-global-dtors-with-atexit -fgnuc-version=4.2.1 -fmax-type-align=16 -o /var/folders/lt/nf3dtk8j16qfsl97d_vgv4dw000lts/T/hello_omp-ea548e.o -x c hello_omp.c</font></div><div class=""><font face="Courier New" class="">clang -cc1 version 12.0.0 based upon LLVM 12.0.0git default target aarch64-apple-darwin20.2.0</font></div><div class=""><font face="Courier New" class="">ignoring nonexistent directory "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/local/include"</font></div><div class=""><font face="Courier New" class="">ignoring nonexistent directory "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/Library/Frameworks"</font></div><div class=""><font face="Courier New" class="">#include "..." search starts here:</font></div><div class=""><font face="Courier New" class="">#include <...> search starts here:</font></div><div class=""><font face="Courier New" class=""> /Users/jcownie/software/clang-12.0.0/arm64/lib/clang/12.0.0/include</font></div><div class=""><font face="Courier New" class=""> /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include</font></div><div class=""><font face="Courier New" class=""> /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks (framework directory)</font></div><div class=""><font face="Courier New" class="">End of search list.</font></div><div class=""><font face="Courier New" class=""> "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld" -demangle -lto_library /Users/jcownie/software/clang-12.0.0/arm64/lib/libLTO.dylib -no_deduplicate -dynamic -arch arm64 -platform_version macos 11.0.0 0.0.0 -syslibroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk -o a.out /var/folders/lt/nf3dtk8j16qfsl97d_vgv4dw000lts/T/hello_omp-ea548e.o -lomp -lSystem</font></div><div class=""><font face="Courier New" class="">ld: library not found for -lomp</font></div><div class=""><font face="Courier New" class="">clang-12: error: linker command failed with exit code 1 (use -v to see invocation)</font></div><div class=""><font face="Courier New" class="">$ </font></div></div></div>

</div>
<br class=""></div></div></body></html>