1

I want to build an application which uses Boost C++ libraries for android platform using cmake toolchain file provided by android NDK. CMake is provided as the build platform.

Here is the command I use:

 cmake -DCMAKE_TOOLCHAIN_FILE=/home/rohith/android-ndk-r16b/build/cmake/android.toolchain.cmake -DBOOST_INCLUDEDIR=/home/rohith/VANETZA/Boost-for-Android-Prebuilt-master/boost_1_64_0/include/ -DBOOST_LIBRARYDIR=/home/rohith/VANETZA/Boost-for-Android-Prebuilt-master/boost_1_64_0/armeabi-v7a/lib  ..

Here is the associated error with regards to finding Boost:

CMake Warning at /usr/local/share/cmake-3.11/Modules/FindBoost.cmake:564 (message):
  Imported targets and dependency information not available for Boost version
  (all versions older than 1.33)
Call Stack (most recent call first):
  /usr/local/share/cmake-3.11/Modules/FindBoost.cmake:903 (_Boost_COMPONENT_DEPENDENCIES)
  /usr/local/share/cmake-3.11/Modules/FindBoost.cmake:1574 (_Boost_MISSING_DEPENDENCIES)
  CMakeLists.txt:43 (find_package)


CMake Error at /usr/local/share/cmake-3.11/Modules/FindBoost.cmake:1959 (message):
  Unable to find the requested Boost libraries.

  Unable to find the Boost header files.  Please set BOOST_ROOT to the root
  directory containing Boost or BOOST_INCLUDEDIR to the directory containing
  Boost's headers.
Call Stack (most recent call first):
  CMakeLists.txt:43 (find_package)


-- Boost_INCLUDE_DIR Boost_INCLUDE_DIR-NOTFOUND.
-- Boost_INCLUDE_DIR Boost_INCLUDE_DIR-NOTFOUND.
CMake Warning at /usr/local/share/cmake-3.11/Modules/FindBoost.cmake:564 (message):
  Imported targets and dependency information not available for Boost version
  (all versions older than 1.33)
Call Stack (most recent call first):
  /usr/local/share/cmake-3.11/Modules/FindBoost.cmake:903 (_Boost_COMPONENT_DEPENDENCIES)
  /usr/local/share/cmake-3.11/Modules/FindBoost.cmake:1574 (_Boost_MISSING_DEPENDENCIES)
  CMakeLists.txt:46 (find_package)


CMake Warning at /usr/local/share/cmake-3.11/Modules/FindBoost.cmake:564 (message):
  Imported targets and dependency information not available for Boost version
  (all versions older than 1.33)
Call Stack (most recent call first):
  /usr/local/share/cmake-3.11/Modules/FindBoost.cmake:903 (_Boost_COMPONENT_DEPENDENCIES)
  /usr/local/share/cmake-3.11/Modules/FindBoost.cmake:1574 (_Boost_MISSING_DEPENDENCIES)
  CMakeLists.txt:46 (find_package)

When I use the clang compiler in the standalone toolchain (which is generated from ANdroid NDK) ndk findBoost is successful:

cmake -DCMAKE_C_COMPILER=/home/rohith/standalone_toolchains/arm/bin/clang -DCMAKE_CXX_COMPILER=/home/rohith/standalone_toolchains/arm/bin/clang++ -DBOOST_INCLUDEDIR=/home/rohith/VANETZA/Boost-for-Android-Prebuilt-master/boost_1_64_0/include -DBOOST_LIBRARYDIR=/home/rohith/VANETZA/Boost-for-Android-Prebuilt-master/boost_1_64_0/armeabi-v7a/lib  ..

Output:

-- Boost_INCLUDE_DIR .
-- Boost_INCLUDE_DIR /home/rohith/VANETZA/Boost-for-Android-Prebuilt-master/boost_1_64_0/include.
-- Boost version: 1.64.0
-- Found the following Boost libraries:
--   date_time

It is able to recognize the boost config file even though the paths to the boost libraries are same for both cmake invokations

I have found the part the in the FindBoost.cmake module that fails:

  message(STATUS "Boost_INCLUDE_DIR ${Boost_INCLUDE_DIR}.")

  # Look for a standard boost header file.
  find_path(Boost_INCLUDE_DIR
    NAMES         boost/config.hpp
    HINTS         ${_boost_INCLUDE_SEARCH_DIRS}
    PATH_SUFFIXES ${_boost_PATH_SUFFIXES}
    )
    message(STATUS "Boost_INCLUDE_DIR ${Boost_INCLUDE_DIR}.")

I edited FindBoost.cmake to print Boost_INCLUDE_DIR variable after it appends the search paths which is supposed find boost/config.hpp for some reason it fails to append the path I have provided when using the cmake toolchain file but succeeds otherwise (As you can see from my output logs)

The boost libraries I'm using are got from Boost-for-Android-Prebuilt Im using Boost library version 1.64 in this repository

cmake version - 3.11

Android NDK - r16b

Host Platform - Ubuntu 14.04

The relevant bit of CMakeLists.txt that I'm invoking:

# Mandatory and optional project dependencies
set(Boost_USE_STATIC_LIBS   ON)
set(Boost_COMPONENTS date_time)
set(Boost_OPTIONAL_COMPONENTS system program_options)
find_package(Boost 1.58 REQUIRED COMPONENTS ${Boost_COMPONENTS})
include(CompatBoostTargets)
# optional components need to be queried seperately (FindBoost bails out when one is missing)
find_package(Boost 1.58 QUIET OPTIONAL_COMPONENTS ${Boost_OPTIONAL_COMPONENTS})
include(CompatBoostTargets)

My main question is why does cmake fail the first time? Does the cmake toolchain file mess up some of the flags (The same flags which are supposed to make an application run on android :p)

And if someone has any experience building boost using cmake or using boost for android please let me know if there's a better a way for me to do this.

NOTE: The main reason I want to build using the cmake toolchain files is cause when I use the standalone toolchain compiler I get run time errorr. I have successfully built and run libpcap on android platform by using the cmake toolchain file

  • 1
    Have you seen this question and my answer to it? https://stackoverflow.com/questions/35791251/possible-causes-for-boost-not-being-found-by-cmake-in-certain-situations – Tsyvarev Mar 27 '18 at 12:47
  • Make sure you use the version of cmake from Android SDK: android.toolchain.cmake may fail on your local cmake. – Alex Cohn Mar 27 '18 at 15:54
  • @Tsyvarev thanks a lot. I hadn't see that question. It worked for me. (Now I can undo all the changes I made to findBoost.cmake and go on my vacation in peace :P) – Rohith Mohan Mar 28 '18 at 09:22
  • @AlexCohn I downloaded the ndk toolchain only (Not along with the SDK). – Rohith Mohan Mar 28 '18 at 09:23
  • I tend to agree with @Tsyvarev that you must change BOOST_ROOT to cross-compile your lib correctly. – Alex Cohn Mar 28 '18 at 16:17

0 Answers0