Android Studio: CMake doesn't find Boost header files

I have included the Boost-Header file in my test project using CMakeLists.txt. My some.cpp can include this header without any error, but I can't seem to work as the header file clearly relies on other Boost headers and doesn't find the files it needs. The location of my files is in the cpp folder and the boost files are in the C: \ boost subdirectory) :

.. \ src \ main \ CPP \ pulse \ RequiredHeader.hpp.

For included files in "RequiredHeader", the compiler looks at:

.. \ src \ main \ cpp \ boost \ boost \ AnotherHeader.hpp.Hit>

CMakeLists.txt (Boost-part)

# ADD BOOST
message("Import Boost...\n")
set(Boost_USE_STATIC_LIBS OFF)
set(Boost_USE_MULTITHREADED ON)
set(Boost_USE_STATIC_RUNTIME OFF)
set(Boost_INCLUDE_DIRS C:/boost_1_64_0/boost)
find_package(Boost 1.64.0)

if(Boost_FOUND)
    message("Boost found! Link libraries...\n")
    include_directories(${Boost_INCLUDE_DIRS})
    target_link_libraries(myDependantLib ${Boost_LIBRARIES})
endif()

      

Your help is greatly appreciated!

Updated question:
How do I tell CMake where are my Boost headers, since it still doesn't find the correct location, with BOOST_ROOT set?

Updated CMakeLists.txt

# ADD BOOST
message("Add boost...\n")
set(Boost_USE_STATIC_LIBS OFF)
set(Boost_USE_MULTITHREADED ON)
set(Boost_USE_STATIC_RUNTIME OFF)
set(BOOST_ROOT C:/boost_1_64_0)
set(BOOST_INCLUDE_DIR C:/boost_1_64_0/boost)

FIND_PACKAGE(Boost 1.64.0 COMPONENTS foreach REQUIRED)

if(Boost_FOUND)
    message("Boost found! Link libraries...\n")
    target_link_libraries(calculator LINK_PUBLIC ${Boost_LIBRARIES})
endif()

      

+3


source to share


1 answer


This post here helped me solve this issue.

Include Boost-Header files and libraries:

set(BOOST_ROOT C:/boost)

      

The path containing the include headers "boost / *. Hpp" and the libraries "stage / lib" or whatever path your compiled files have been compiled into.
Then you need to include the include and libs headers. In the default case, headers are stored in the same directory as the root directory (since the "boost" folder is automatically created) and libraries, as described in the "stage / lib" section. Otherwise, it should be the "include" and "lib" of your output directory, while the boost version should match the one specified in the version.hpp file in the "boost" folder:

set( Boost_INCLUDE_DIR ${BOOST_ROOT}/include )
set( Boost_LIBRARY_DIR ${BOOST_ROOT}/lib )
set( Boost_Version 1_64 )

find_package( Boost ${Boost_Version} COMPONENTS system thread )
if( Boost_FOUND )
    target_include_directories( <your_lib> PUBLIC/PRIVATE ${Boost_INCLUDE_DIR} )  


    # its possible to include boost to system path too:  
    # include_directories( SYSTEM ${Boost_INCLUDE_DIR} )

    link_directories( ${Boost_LIBRARY_DIR} )
    target_link_libraries( <your_lib> ${Boost_LIBRARIES} )
endif()

      



Then I was able to simply:

#include <boost/random.hpp>
#include <boost/whatever.hpp>

      

This worked for me under the following conditions:

  • Android Studio 2.3.1 and 3.0
  • NDK 14.1
  • Boost 1.56.0 and 1.64.0
  • Windows 10

If further explanation is needed, please comment on your concerns!

+2


source







All Articles