title: How to compile LLVM/Clang for Android?
body: <p>I'm trying to compile LLVM/Clang 8.0.1 for Android with Cmake (since autotools i used before are no longer supported) on mac.</p>
  
  <p>I'm using <a href="https://github.com/llvm/llvm-project.git" rel="nofollow noreferrer">https://github.com/llvm/llvm-project.git</a>.
  In build dir i'm using the following configure script (followed <a href="https://llvm.org/docs/HowToCrossCompileLLVM.html#configuring-cmake" rel="nofollow noreferrer">manuals</a>):</p>
  
  <pre><code>cmake ../llvm \
  -DCMAKE_INSTALL_PREFIX=/Users/asmirnov/Library/Android/llvm_android_arm \
  -DLLVM_ENABLE_PROJECTS=clang \
  -DLLVM_ENABLE_TERMINFO=OFF \
  -DLLVM_ENABLE_THREADS=OFF \
  -DCMAKE_BUILD_TYPE=Release \
  -DLLVM_TARGETS_TO_BUILD="ARM;X86" \
  -DLIBCLANG_BUILD_STATIC=ON \
  -DLLVM_INCLUDE_TESTS=OFF \
  -DLLVM_ENABLE_ZLIB=OFF \
  \
  -DCMAKE_CROSSCOMPILING=True \
  -DLLVM_TABLEGEN=/Users/asmirnov/Library/Android/llvm/bin/llvm-tblgen \
  -DCLANG_TABLEGEN=/Users/asmirnov/Documents/dev/src/llvm-project/build/bin/clang-tblgen \
  -DLLVM_DEFAULT_TARGET_TRIPLE=arm-linux-gnueabihf \
  -DLLVM_TARGET_ARCH=ARM \
  -DBUILD_SHARED_LIBS=ON \
  -DLLVM_ENABLE_PIC=False \
  -DCMAKE_TOOLCHAIN_FILE=/Users/asmirnov/Library/Android/ndk/android-ndk-r20/build/cmake/android.toolchain.cmake
  </code></pre>
  
  <p>As you can see i'm using CMake toolchain file from Android NDK (20).
  Also i've compiled it locally and passing <code>LLVM_TABLEGEN</code> and <code>CLANG_TABLEGEN</code>.
  Configuration went successfully, but during the build i get the following errors:</p>
  
  <pre><code>/Users/asmirnov/Documents/dev/src/llvm-project/llvm/lib/Transforms/Hello/Hello.cpp:27: error: undefined reference to 'llvm::Pass::~Pass()'
  /Users/asmirnov/Documents/dev/src/llvm-project/llvm/lib/Transforms/Hello/Hello.cpp:33: error: undefined reference to 'llvm::errs()'
  /Users/asmirnov/Documents/dev/src/llvm-project/llvm/lib/Transforms/Hello/Hello.cpp:34: error: undefined reference to 'llvm::errs()'
  /Users/asmirnov/Documents/dev/src/llvm-project/llvm/lib/Transforms/Hello/Hello.cpp:34: error: undefined reference to 'llvm::Value::getName() const'
  /Users/asmirnov/Documents/dev/src/llvm-project/llvm/lib/Transforms/Hello/Hello.cpp:34: error: undefined reference to 'llvm::raw_ostream::write_escaped(llvm::StringRef, bool)'
  /Users/asmirnov/Documents/dev/src/llvm-project/llvm/include/llvm/Support/raw_ostream.h:149: error: undefined reference to 'llvm::raw_ostream::write(unsigned char)'
  /Users/asmirnov/Documents/dev/src/llvm-project/llvm/include/llvm/Support/raw_ostream.h:174: error: undefined reference to 'llvm::raw_ostream::write(char const*, unsigned int)'
  /Users/asmirnov/Documents/dev/src/llvm-project/llvm/lib/Transforms/Hello/Hello.cpp:45: error: undefined reference to 'llvm::Pass::~Pass()'
  /Users/asmirnov/Documents/dev/src/llvm-project/llvm/lib/Transforms/Hello/Hello.cpp:51: error: undefined reference to 'llvm::errs()'
  /Users/asmirnov/Documents/dev/src/llvm-project/llvm/lib/Transforms/Hello/Hello.cpp:52: error: undefined reference to 'llvm::errs()'
  /Users/asmirnov/Documents/dev/src/llvm-project/llvm/lib/Transforms/Hello/Hello.cpp:52: error: undefined reference to 'llvm::Value::getName() const'
  /Users/asmirnov/Documents/dev/src/llvm-project/llvm/lib/Transforms/Hello/Hello.cpp:52: error: undefined reference to 'llvm::raw_ostream::write_escaped(llvm::StringRef, bool)'
  /Users/asmirnov/Documents/dev/src/llvm-project/llvm/include/llvm/PassSupport.h:98: error: undefined reference to 'llvm::PassRegistry::getPassRegistry()'
  /Users/asmirnov/Documents/dev/src/llvm-project/llvm/include/llvm/PassSupport.h:98: error: undefined reference to 'llvm::PassRegistry::registerPass(llvm::PassInfo const&amp;, bool)'
  /Users/asmirnov/Documents/dev/src/llvm-project/llvm/include/llvm/PassSupport.h:98: error: undefined reference to 'llvm::PassRegistry::getPassRegistry()'
  /Users/asmirnov/Documents/dev/src/llvm-project/llvm/include/llvm/PassSupport.h:98: error: undefined reference to 'llvm::PassRegistry::registerPass(llvm::PassInfo const&amp;, bool)'
  CMakeFiles/LLVMHello.dir/Hello.cpp.o:Hello.cpp:vtable for (anonymous namespace)::Hello: error: undefined reference to 'llvm::Pass::~Pass()'
  CMakeFiles/LLVMHello.dir/Hello.cpp.o:Hello.cpp:vtable for (anonymous namespace)::Hello: error: undefined reference to 'llvm::Pass::getPassName() const'
  CMakeFiles/LLVMHello.dir/Hello.cpp.o:Hello.cpp:vtable for (anonymous namespace)::Hello: error: undefined reference to 'llvm::Pass::print(llvm::raw_ostream&amp;, llvm::Module const*) const'
  CMakeFiles/LLVMHello.dir/Hello.cpp.o:Hello.cpp:vtable for (anonymous namespace)::Hello: error: undefined reference to 'llvm::FunctionPass::createPrinterPass(llvm::raw_ostream&amp;, std::__ndk1::basic_string&lt;char, std::__ndk1::char_traits&lt;char&gt;, std::__ndk1::allocator&lt;char&gt; &gt; const&amp;) const'
  CMakeFiles/LLVMHello.dir/Hello.cpp.o:Hello.cpp:vtable for (anonymous namespace)::Hello: error: undefined reference to 'llvm::FunctionPass::assignPassManager(llvm::PMStack&amp;, llvm::PassManagerType)'
  CMakeFiles/LLVMHello.dir/Hello.cpp.o:Hello.cpp:vtable for (anonymous namespace)::Hello: error: undefined reference to 'llvm::Pass::preparePassManager(llvm::PMStack&amp;)'
  CMakeFiles/LLVMHello.dir/Hello.cpp.o:Hello.cpp:vtable for (anonymous namespace)::Hello: error: undefined reference to 'llvm::FunctionPass::getPotentialPassManagerType() const'
  CMakeFiles/LLVMHello.dir/Hello.cpp.o:Hello.cpp:vtable for (anonymous namespace)::Hello: error: undefined reference to 'llvm::Pass::getAnalysisUsage(llvm::AnalysisUsage&amp;) const'
  CMakeFiles/LLVMHello.dir/Hello.cpp.o:Hello.cpp:vtable for (anonymous namespace)::Hello: error: undefined reference to 'llvm::Pass::releaseMemory()'
  CMakeFiles/LLVMHello.dir/Hello.cpp.o:Hello.cpp:vtable for (anonymous namespace)::Hello: error: undefined reference to 'llvm::Pass::getAdjustedAnalysisPointer(void const*)'
  CMakeFiles/LLVMHello.dir/Hello.cpp.o:Hello.cpp:vtable for (anonymous namespace)::Hello: error: undefined reference to 'llvm::Pass::getAsImmutablePass()'
  CMakeFiles/LLVMHello.dir/Hello.cpp.o:Hello.cpp:vtable for (anonymous namespace)::Hello: error: undefined reference to 'llvm::Pass::getAsPMDataManager()'
  CMakeFiles/LLVMHello.dir/Hello.cpp.o:Hello.cpp:vtable for (anonymous namespace)::Hello: error: undefined reference to 'llvm::Pass::verifyAnalysis() const'
  CMakeFiles/LLVMHello.dir/Hello.cpp.o:Hello.cpp:vtable for (anonymous namespace)::Hello: error: undefined reference to 'llvm::Pass::dumpPassStructure(unsigned int)'
  CMakeFiles/LLVMHello.dir/Hello.cpp.o:Hello.cpp:vtable for (anonymous namespace)::Hello2: error: undefined reference to 'llvm::Pass::~Pass()'
  CMakeFiles/LLVMHello.dir/Hello.cpp.o:Hello.cpp:vtable for (anonymous namespace)::Hello2: error: undefined reference to 'llvm::Pass::getPassName() const'
  CMakeFiles/LLVMHello.dir/Hello.cpp.o:Hello.cpp:vtable for (anonymous namespace)::Hello2: error: undefined reference to 'llvm::Pass::print(llvm::raw_ostream&amp;, llvm::Module const*) const'
  CMakeFiles/LLVMHello.dir/Hello.cpp.o:Hello.cpp:vtable for (anonymous namespace)::Hello2: error: undefined reference to 'llvm::FunctionPass::createPrinterPass(llvm::raw_ostream&amp;, std::__ndk1::basic_string&lt;char, std::__ndk1::char_traits&lt;char&gt;, std::__ndk1::allocator&lt;char&gt; &gt; const&amp;) const'
  CMakeFiles/LLVMHello.dir/Hello.cpp.o:Hello.cpp:vtable for (anonymous namespace)::Hello2: error: undefined reference to 'llvm::FunctionPass::assignPassManager(llvm::PMStack&amp;, llvm::PassManagerType)'
  CMakeFiles/LLVMHello.dir/Hello.cpp.o:Hello.cpp:vtable for (anonymous namespace)::Hello2: error: undefined reference to 'llvm::Pass::preparePassManager(llvm::PMStack&amp;)'
  CMakeFiles/LLVMHello.dir/Hello.cpp.o:Hello.cpp:vtable for (anonymous namespace)::Hello2: error: undefined reference to 'llvm::FunctionPass::getPotentialPassManagerType() const'
  CMakeFiles/LLVMHello.dir/Hello.cpp.o:Hello.cpp:vtable for (anonymous namespace)::Hello2: error: undefined reference to 'llvm::Pass::releaseMemory()'
  CMakeFiles/LLVMHello.dir/Hello.cpp.o:Hello.cpp:vtable for (anonymous namespace)::Hello2: error: undefined reference to 'llvm::Pass::getAdjustedAnalysisPointer(void const*)'
  CMakeFiles/LLVMHello.dir/Hello.cpp.o:Hello.cpp:vtable for (anonymous namespace)::Hello2: error: undefined reference to 'llvm::Pass::getAsImmutablePass()'
  CMakeFiles/LLVMHello.dir/Hello.cpp.o:Hello.cpp:vtable for (anonymous namespace)::Hello2: error: undefined reference to 'llvm::Pass::getAsPMDataManager()'
  CMakeFiles/LLVMHello.dir/Hello.cpp.o:Hello.cpp:vtable for (anonymous namespace)::Hello2: error: undefined reference to 'llvm::Pass::verifyAnalysis() const'
  CMakeFiles/LLVMHello.dir/Hello.cpp.o:Hello.cpp:vtable for (anonymous namespace)::Hello2: error: undefined reference to 'llvm::Pass::dumpPassStructure(unsigned int)'
  clang++: error: linker command failed with exit code 1 (use -v to see invocation)
  make[2]: *** [lib/LLVMHello.so] Error 1
  make[1]: *** [lib/Transforms/Hello/CMakeFiles/LLVMHello.dir/all] Error 2
  make[1]: *** Waiting for unfinished jobs....
  </code></pre>
  
  <p>Am i doing anything wrong? Is it LLVM/Clang bug? Any workaround?</p>