0

I am working on an algorithm library that provides pre-compiled .so file for an Android application. We want to use PyTorch C++ API in our library so I put some effort on it. However I encountered some problems when trying to build with CMake.

Building works well without using android.cmake.toolchain provided in the NDK, and the compiled program behaves as expected. Things go wrong when I try to use android.cmake.toolchain to build library, the following two lines in TorchConfig.cmake(this file is provided by Torch) went wrong weirdly:

find_package(Caffe2 REQUIRED PATHS ${CMAKE_CURRENT_LIST_DIR}/../Caffe2) [Line 40] 
find_library(C10_LIBRARY c10 PATHS "${TORCH_INSTALL_PREFIX}/lib") [Line 47]

Although those commands used PATHS to specify absolute path, CMake insists that those package and library cannot be found. I tried use message to print out those path and check, the files CMaKe should be looking for (Caffe2Config.cmake and libc10.so) do exist in the path specified.

I am aware that android toolchain will change the compilers to be used (to bundled clang), but I cannot see the reason why cmake behaves oddly in my case.

LIU Qingyuan
  • 524
  • 5
  • 18
  • 2
    The problem could be that `android.cmake.toolchain` adjust `find_` commands to search only **under sysroot**. See [that question](https://stackoverflow.com/questions/35791251/possible-causes-for-boost-not-being-found-by-cmake-in-certain-situations) and my answer to it for more info. – Tsyvarev Dec 19 '19 at 12:08
  • That's the reason and the solution I am looking for, thx! – LIU Qingyuan Dec 20 '19 at 01:17

0 Answers0