Possible causes for Boost not being found by CMake in certain situations?

When cross-compiling, the toolchain file normally sets the variable CMAKE_FIND_ROOT_PATH. Combined with the CMAKE_FIND_ROOT_PATH_MODE_LIBRARY variable set to ONLY, CMAKE_FIND_ROOT_PATH variable is used as effective chroot for find_library calls, so only libraries under the given prefix(es) are searched.

Analogue variables exist to adjust the behavior for find_path (used for searching include paths) and find_program.

THe toolchain file you use actually sets CMAKE_FIND_ROOT_PATH at line 1521:

set( CMAKE_FIND_ROOT_PATH "${ANDROID_TOOLCHAIN_ROOT}/bin"
    "${ANDROID_TOOLCHAIN_ROOT}/${ANDROID_TOOLCHAIN_MACHINE_NAME}"
    "${ANDROID_SYSROOT}"
    "${CMAKE_INSTALL_PREFIX}"
    "${CMAKE_INSTALL_PREFIX}/share" )

and below sets CMAKE_FIND_ROOT_PATH_MODE_* variables to ONLY. So you need to have Boost installed under one of these directories, and give hints (like BOOST_ROOT) relative to it.

Note, that Boost should be built for the target platform (Android NDK in you case), not for the platform where you cross-compile (Linux).

Leave a Comment