[SOLVED] Trying to compile RPC C++. Cannot cross compile libbacktrace

Hello,

I’m using Docker android_demo to compile RPC_CPP, but cannot finish this task. Some strange behaviour I encounter, e.g.:

  1. I’m trying to turn off libbacktrace, but I CAN’T. I’m using v0.9.dev0. I have used following command:
cmake \
  -DCMAKE_TOOLCHAIN_FILE=${ANDROID_NDK_HOME}/build/cmake/android.toolchain.cmake \
  -DCMAKE_C_COMPILER=${ANDROID_NDK_HOME}toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android28-clang \
  -DCMAKE_CXX_COMPILER=${ANDROID_NDK_HOME}toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android28-clang++ \
  -DCMAKE_FIND_ROOT_PATH=${ANDROID_NDK_HOME}toolchains/llvm/prebuilt/linux-x86_64/ \
  -DUSE_LLVM=${ANDROID_NDK_HOME}toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-config \
  -DUSE_RPC=ON \
  -DUSE_LIBBACKTRACE=OFF \
  -DUSE_CPP_RPC=ON \
  -DUSE_PROFILER=OFF \
  -DCMAKE_SYSTEM_NAME=Linux \
  -DCMAKE_SYSTEM_VERSION=1 \
  -DCMAKE_HOST=aarch64-linux-android \
  -DMACHINE_NAME=aarch64-linux-android \
  -DCMAKE_FIND_ROOT_PATH_MODE_PROGRAM=NEVER \
  -DCMAKE_FIND_ROOT_PATH_MODE_LIBRARY=ONLY \
  -DUSE_SORT=ON \
   .. && \
 make -j10 runtime

But I’m getting following error message:

(...)
4
#6 4.353 -- Performing Test SUPPORT_CXX14 - Success
#6 4.359 -- Autoset: USE_LIBBACKTRACE=ON in Linux
#6 4.359 -- Building with libbacktrace...
#6 4.412 -- Building with TVM Map...
(...)
#6 4.742 Scanning dependencies of target project_libbacktrace
#6 4.746 Scanning dependencies of target tvm_libinfo_objs
#6 4.753 [  9%] Creating directories for 'project_libbacktrace'
#6 4.756 [  9%] Building CXX object CMakeFiles/tvm_libinfo_objs.dir/src/support/libinfo.cc.o
#6 4.819 [  9%] No download step for 'project_libbacktrace'
#6 4.844 [  9%] No patch step for 'project_libbacktrace'
#6 4.844 [  9%] No update step for 'project_libbacktrace'
#6 4.844 [  9%] No checkout step for 'project_libbacktrace'
#6 4.882 [  9%] Performing configure step for 'project_libbacktrace'
#6 4.998 checking build system type... x86_64-pc-linux-gnu
(...)
#6 5.130 checking whether we are cross compiling... configure: error: in `/workspace/build/libbacktrace':
#6 5.161 configure: error: cannot run C compiled programs.
#6 5.161 If you meant to cross compile, use `--host'.
#6 5.161 See `config.log' for more details
#6 5.183 make[3]: *** [libbacktrace/src/project_libbacktrace-stamp/project_libbacktrace-configure] Error 1
#6 5.183 CMakeFiles/project_libbacktrace.dir/build.make:107: recipe for target 'libbacktrace/src/project_libbacktrace-stamp/project_libbacktrace-configure' failed
#6 5.183 make[2]: *** [CMakeFiles/project_libbacktrace.dir/all] Error 2

You probably have a config.cmake in your build directory. The settings in it override command line settings. Edit the set(USE_LIBBACKTRACE AUTO) line in it to set(USE_LIBBACKTRACE OFF).

I’m pretty sure I do not have config.cmake, and some magic is under the hood, my slice of dockerfile:

# clone repository
RUN git clone -b v0.9.dev0 --depth 1 --recursive --shallow-submodules https://github.com/apache/tvm /workspace

ENV MACHINE_NAME="aarch64-linux-android"
# build library
RUN mkdir -p /workspace/build && \
 cd /workspace/build && \
 cmake \
  -DCMAKE_TOOLCHAIN_FILE=${ANDROID_NDK_HOME}/build/cmake/android.toolchain.cmake \
  -DCMAKE_C_COMPILER=${ANDROID_NDK_HOME}toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android28-clang \
  -DCMAKE_CXX_COMPILER=${ANDROID_NDK_HOME}toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android28-clang++ \
  -DCMAKE_FIND_ROOT_PATH=${ANDROID_NDK_HOME}toolchains/llvm/prebuilt/linux-x86_64/ \
  -DUSE_LLVM=${ANDROID_NDK_HOME}toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-config \
  -DUSE_RPC=ON \
  -DUSE_LIBBACKTRACE=OFF \
  -DUSE_CPP_RPC=ON \
  -DUSE_PROFILER=OFF \
  -DCMAKE_SYSTEM_NAME=Linux \
  -DCMAKE_SYSTEM_VERSION=1 \
  -DCMAKE_HOST=aarch64-linux-android \
  -DCMAKE_FIND_ROOT_PATH_MODE_PROGRAM=NEVER \
  -DCMAKE_FIND_ROOT_PATH_MODE_LIBRARY=ONLY \
  -DUSE_SORT=ON \
   .. && \
 make -j10 runtime

Even stranger situation, I have removed DCMAKE_C_COMPILER option and I’m almost finished compilation, error at the end:

#6 33.58 [100%] Linking CXX shared library libtvm_runtime.so
#6 33.63 /opt/android-sdk-linux/ndk/21.3.6528147/toolchains/llvm/prebuilt/linux-x86_64/bin/../lib/gcc/aarch64-linux-android/4.9.x/../../../../aarch64-linux-android/bin/ld: libbacktrace/lib/libbacktrace.a(fileline.o): Relocations in generic ELF (EM: 62)
#6 33.63 /opt/android-sdk-linux/ndk/21.3.6528147/toolchains/llvm/prebuilt/linux-x86_64/bin/../lib/gcc/aarch64-linux-android/4.9.x/../../../../aarch64-linux-android/bin/ld: libbacktrace/lib/libbacktrace.a(fileline.o): Relocations in generic ELF (EM: 62)
#6 33.63 /opt/android-sdk-linux/ndk/21.3.6528147/toolchains/llvm/prebuilt/linux-x86_64/bin/../lib/gcc/aarch64-linux-android/4.9.x/../../../../aarch64-linux-android/bin/ld: libbacktrace/lib/libbacktrace.a(fileline.o): Relocations in generic ELF (EM: 62)
#6 33.63 libbacktrace/lib/libbacktrace.a: error adding symbols: File in wrong format
#6 33.63 clang++: error: linker command failed with exit code 1 (use -v to see invocation)
#6 33.63 make[3]: *** [libtvm_runtime.so] Error 1
#6 33.63 CMakeFiles/tvm_runtime.dir/build.make:149: recipe for target 'libtvm_runtime.so' failed
#6 33.63 make[2]: *** [CMakeFiles/tvm_runtime.dir/all] Error 2
#6 33.63 CMakeFiles/Makefile2:1153: recipe for target 'CMakeFiles/tvm_runtime.dir/all' failed
#6 33.63 CMakeFiles/Makefile2:1197: recipe for target 'CMakeFiles/runtime.dir/rule' failed
#6 33.63 make[1]: *** [CMakeFiles/runtime.dir/rule] Error 2
#6 33.63 Makefile:617: recipe for target 'runtime' failed
#6 33.63 make: *** [runtime] Error 2

I think that my issue is connected with this PR: https://github.com/apache/tvm/pull/7917

@tkonolige You were almost right. There was not cmake.config in build directory, but somehow cmake has default values without it. I have copied it, and run sed to change values, and it works correctly. Thanks