0

I am trying to build a native Android project that requires Boost library. I have built Boost for the platforms I am targeting using this git project. But for some reason find_package() for Boost fails to find the Boost header paths

Below is the project structure and for the Android app, and location where I have placed the Boost library.

android_app
  ├── src
  │   └──<folder>
  │      └──<folder>
  │         └──CMakeLists.txt
  └── lib
      └── boost_armeabi-v7a
          ├── include
          │   └── boost_1_68_0
          │       └──boost
          │          ├──align.hpp
          │          ├──......
          │          └──config.hpp
          └── lib
              ├──libboost_atomic.a
              ├──......
              └──libboost_wserialization.a

In the CMake file I have configured like this

set(Boost_NO_SYSTEM_PATHS ON)
set(Boost_NO_BOOST_CMAKE ON)

set(LOCAL_LIB_DIR "${PROJECT_SOURCE_DIR}/../../../lib")
set(Boost_ADDITIONAL_VERSIONS   "1.68.0")

set(BOOST_INCLUDEDIR "${LOCAL_LIB_DIR}/boost_${ANDROID_ABI}/include")
set(BOOST_LIBRARYDIR "${LOCAL_LIB_DIR}/boost_${ANDROID_ABI}/lib")

find_package(Boost REQUIRED)

Below error is the error iam getting with find_package.

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.

I added some message statements and finally narrowed down to this piece of code in the FindBoost CMake file (3.10.2) installed from Android Studio

find_path(Boost_INCLUDE_DIR
        NAMES         boost/config.hpp
        HINTS         ${_boost_INCLUDE_SEARCH_DIRS}
        PATH_SUFFIXES ${_boost_PATH_SUFFIXES}
    )

Dumping there variables, one of the combination for {_boost_INCLUDE_SEARCH_DIRS}/{_boost_PATH_SUFFIXES} should be valid for my path, but after this executes, Boost_INCLUDE_DIR is set as NOTFOUND. I have no idea why this fails.

One of the _boost_INCLUDE_SEARCH_DIRS value is /home/<user>/<path-to-repo>/app/lib/boost_armeabi-v7a/include and one of value in PATH_SUFFIXES is boost_1_68_0. Can some one help me figure out why this is failing?

vre
  • 6,041
  • 1
  • 25
  • 39
user3279954
  • 556
  • 2
  • 7
  • 22
  • Your quite outdated CMake version seems not to support this Boost version. Boost naming scheme changed after Boost version 1.65.0 You can try to populate the Boost additional versions variable, e.g. `set(Boost_ADDITIONAL_VERSIONS "1.68.0" "1.68")`. But I doubt it will work because of the aforementioned reason. If possible try a newer CMake version or an older Boost version (1.65) – vre Apr 30 '20 at 06:40
  • In any case, *include directory* (`BOOST_INCLUDEDIR`) is the directory which **immediately** contains header files which could be requested e.g. with `#include `. But you specify directory, which doesn't immediately contain this file: it has `boost_1_68_0` subdirectory, but not `boost` one. You need to set include directory as `set(BOOST_INCLUDEDIR "${LOCAL_LIB_DIR}/boost_${ANDROID_ABI}/include/boost_1_68_0")`. – Tsyvarev Apr 30 '20 at 07:30
  • @Tsyvarev I copied the boost directory under `boost_${ANDROID_ABI}` and under `boost_${ANDROID_ABI}/include` in addition to how its present above but still it fails. How does find_path work when i tried this simple find_path `find_path(_TEST_Path bash HINTS /bin) message(STATUS ${_TEST_Path})` – user3279954 Apr 30 '20 at 21:01
  • "How does find_path work...?" - `find_path` just searched the file, specified by `NAMES`, in the given and well-known system-specific directories. BTW, you may set `Boost_DEBUG` variable (e.g. from the command line: `-DBoost_DEBUG=ON`) and check which paths are actually searched. – Tsyvarev Apr 30 '20 at 21:54
  • Well, actually there is some specific about `find_*` commands when **cross-compiling**. See that question: https://stackoverflow.com/q/35791251/3440745. – Tsyvarev Apr 30 '20 at 22:05

0 Answers0