<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto">Also if you want to see how I setup my sysroot you can take a look at: <a href="https://github.com/plotfi/llvm-pi/blob/master/Dockerfile">https://github.com/plotfi/llvm-pi/blob/master/Dockerfile</a><div><br></div><div>-Puyan<br><br><div dir="ltr">Sent from my iPhone</div><div dir="ltr"><br><blockquote type="cite">On Aug 20, 2020, at 2:38 AM, David Spickett via cfe-dev <cfe-dev@lists.llvm.org> wrote:<br><br></blockquote></div><blockquote type="cite"><div dir="ltr"><span>Hi Andy,</span><br><span></span><br><span>Assuming you are compiling with clang, I think -target and --sysroot</span><br><span>need to be added to CMAKE_CXX_FLAGS instead of being cmake arguments</span><br><span>themselves.</span><br><span></span><br><span>"However, if you’re using Clang, the driver might not be up-to-date</span><br><span>with your specific Linux distribution, version or GCC layout, so</span><br><span>you’ll need to fudge.</span><br><span></span><br><span>In addition to the ones above, you’ll also need:"</span><br><span></span><br><span>Means you'll need extra CMAKE_CXX_FLAGS. (I also made the same mistake</span><br><span>on first reading) So try:</span><br><span>-DCMAKE_CXX_FLAGS="-target arm-linux-gnueabihf</span><br><span>--sysroot=/usr/arm-linux-gnueabihf"</span><br><span></span><br><span>Also I think (not tried your exact config) you need to tell cmake you</span><br><span>want to use clang by doing:</span><br><span>-DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++</span><br><span></span><br><span>If you're using GCC, skip the target and sysroot CFLAGS. Also I found</span><br><span>that I had to explicitly give cmake the gcc name (similar to above):</span><br><span>-DCMAKE_C_COMPILER=arm-linux-gnueabihf-gcc</span><br><span>-DCMAKE_CXX_COMPILER=arm-linux-gnueabihf-g++-5</span><br><span>I have a feeling CMake should find this on its own but I don't know</span><br><span>enough to say.</span><br><span></span><br><span>If the default triple is still x86 by that point you can set that</span><br><span>with: -DLLVM_DEFAULT_TARGET_TRIPLE=arm-linux-gnueabihf</span><br><span>(probably won't be an issue)</span><br><span></span><br><span>Thanks,</span><br><span>David Spickett.</span><br><span></span><br><span>On Thu, 20 Aug 2020 at 03:15, Dongdong Yang via cfe-dev</span><br><span><cfe-dev@lists.llvm.org> wrote:</span><br><blockquote type="cite"><span></span><br></blockquote><blockquote type="cite"><span>I can get llvm source code and the information “cross-compiling from x86_64 to ARM” from https://llvm.org/docs/HowToCrossCompileLLVM.html. However, I still fail to build clang for ARM. It is strange, I have already set a target with "   -target arm-linux-gnueabihf  "  .  I am describing the failure progress as below. Expecting any idea.</span><br></blockquote><blockquote type="cite"><span></span><br></blockquote><blockquote type="cite"><span></span><br></blockquote><blockquote type="cite"><span></span><br></blockquote><blockquote type="cite"><span>The build steps:</span><br></blockquote><blockquote type="cite"><span>cd llvm-project</span><br></blockquote><blockquote type="cite"><span>mkdir build</span><br></blockquote><blockquote type="cite"><span>cd build</span><br></blockquote><blockquote type="cite"><span>cmake -DLLVM_ENABLE_PROJECTS=clang -G "Unix Makefiles"</span><br></blockquote><blockquote type="cite"><span>make</span><br></blockquote><blockquote type="cite"><span>// After I built host llvm-tblgen  and clang-tblgen, I begin to return to build arm target clang as below steps:</span><br></blockquote><blockquote type="cite"><span>cd ..</span><br></blockquote><blockquote type="cite"><span>mkdir build_arm_onx86</span><br></blockquote><blockquote type="cite"><span>cd build_arm_onx86</span><br></blockquote><blockquote type="cite"><span>mkdir stall_prefix</span><br></blockquote><blockquote type="cite"><span>cmake -G "Unix Makefiles" -DCMAKE_CROSSCOMPILING=True  -DCMAKE_INSTALL_PREFIX=./stall_prefix  -DLLVM_TABLEGEN=/home_2t/workspace/llvm_clang/llvm-project/build/bin/llvm-tblgen -DCLANG_TABLEGEN=/home_2t/workspace/llvm_clang/llvm-project/build/bin/clang-tblgen -DLLVM_TARGET_ARCH=ARM -DLLVM_TARGETS_TO_BUILD=ARM  -target arm-linux-gnueabihf  -DLLVM_ENABLE_PROJECTS="clang;libcxx;libcxxabi"  ../llvm    2>&1 | tee out_cofiguration.txt</span><br></blockquote><blockquote type="cite"><span>make  2>&1 | tee out_make.txt</span><br></blockquote><blockquote type="cite"><span></span><br></blockquote><blockquote type="cite"><span>The result:</span><br></blockquote><blockquote type="cite"><span></span><br></blockquote><blockquote type="cite"><span>build_arm_onx86$ file bin/clang-12</span><br></blockquote><blockquote type="cite"><span>bin/clang-12: ELF 64-bit LSB executable, x86-64, version 1 (GNU/Linux), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 2.6.32, BuildID[sha1]=3b669c10e300bb5d9bb96cfb77f927ce95728ca6, not stripped</span><br></blockquote><blockquote type="cite"><span></span><br></blockquote><blockquote type="cite"><span>build_arm_onx86$ bin/clang --version</span><br></blockquote><blockquote type="cite"><span>clang version 12.0.0 (https://github.com/llvm/llvm-project.git 3948341fa5fab2695b0df95edc248fe959e40664)</span><br></blockquote><blockquote type="cite"><span>Target: x86_64-unknown-linux-gnu</span><br></blockquote><blockquote type="cite"><span>Thread model: posix</span><br></blockquote><blockquote type="cite"><span>InstalledDir: /home_2t/workspace/llvm_clang/llvm-project/build_arm_onx86/bin</span><br></blockquote><blockquote type="cite"><span></span><br></blockquote><blockquote type="cite"><span>Seems it failed from the configuration as attached cmake output log.</span><br></blockquote><blockquote type="cite"><span>-- LLVM host triple: x86_64-unknown-linux-gnu</span><br></blockquote><blockquote type="cite"><span>-- LLVM default target triple: x86_64-unknown-linux-gnu</span><br></blockquote><blockquote type="cite"><span></span><br></blockquote><blockquote type="cite"><span></span><br></blockquote><blockquote type="cite"><span>Thanks in advance</span><br></blockquote><blockquote type="cite"><span></span><br></blockquote><blockquote type="cite"><span></span><br></blockquote><blockquote type="cite"><span>Best Regards,</span><br></blockquote><blockquote type="cite"><span>Andy</span><br></blockquote><blockquote type="cite"><span></span><br></blockquote><blockquote type="cite"><span>On Thu, Aug 13, 2020 at 7:32 PM Dongdong Yang <contribute.kernel@gmail.com> wrote:</span><br></blockquote><blockquote type="cite"><blockquote type="cite"><span></span><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><span>May I ask how to build clang for arm on x86 linux ubuntu box? And how to use  sysroot  to cross compile clang  libc++  for arm on x86 linux?   Appreciate any guidance.</span><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><span></span><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><span>Thanks,</span><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><span>Andy</span><br></blockquote></blockquote><blockquote type="cite"><span></span><br></blockquote><blockquote type="cite"><span>_______________________________________________</span><br></blockquote><blockquote type="cite"><span>cfe-dev mailing list</span><br></blockquote><blockquote type="cite"><span>cfe-dev@lists.llvm.org</span><br></blockquote><blockquote type="cite"><span>https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev</span><br></blockquote><span>_______________________________________________</span><br><span>cfe-dev mailing list</span><br><span>cfe-dev@lists.llvm.org</span><br><span>https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev</span><br></div></blockquote></div></body></html>