AirSim/Unity build on macOS ('boost/filesystem.hpp' file not found)

501 Views Asked by At

I am trying to install AirSim/Unity on MacOS Catalina. When I run Unity/build.sh I get a fatal error:

In file included from /Users/nfirbas/Documents/AirSim/Unity/AirLibWrapper/AirsimWrapper/Source/Logger.cpp:3:
/Users/nfirbas/Documents/AirSim/Unity/AirLibWrapper/AirsimWrapper/Source/Logger.h:6:11: fatal error: 'boost/filesystem.hpp' file not found
        #include <boost/filesystem.hpp>
                 ^~~~~~~~~~~~~~~~~~~~~~
1 warning and 1 error generated.
make[2]: *** [CMakeFiles/AirsimWrapper.dir/Source/Logger.cpp.o] Error 1
make[2]: *** Waiting for unfinished jobs....

I have installed boost with brew. It's my first time working with brew so I assume that I need to edit my CMakeList.txt. I tried changing it myself but I didn't get it working.

My CMakeLists.txt:

cmake_minimum_required(VERSION 3.5.0)

if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
    set(MACOSX TRUE)
endif()

find_path(AIRSIM_ROOT NAMES AirSim.sln PATHS ".." "../.." "../../.." "../../../.." "../../../../.." "../../../../../..")
message(AirSim Root directory: ${AIRSIM_ROOT})

LIST(APPEND CMAKE_MODULE_PATH "${AIRSIM_ROOT}/cmake/cmake-modules")
LIST(APPEND CMAKE_MODULE_PATH "${RPC_SOURCE_DIR}/cmake")
LIST(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")


INCLUDE("${AIRSIM_ROOT}/cmake/cmake-modules/CommonSetup.cmake")
INCLUDE("${CMAKE_CURRENT_SOURCE_DIR}/cmake/rpc-setup.cmake")
INCLUDE("${CMAKE_CURRENT_SOURCE_DIR}/cmake/mav-setup.cmake")
INCLUDE("${CMAKE_CURRENT_SOURCE_DIR}/cmake/airlib-setup.cmake")
INCLUDE("${CMAKE_CURRENT_SOURCE_DIR}/cmake/airsimwrapper-setup.cmake")

IncludeEigen()

project(AirsimWrapper VERSION 0)

# RPC includes & source files
BuildRpc()
# MavLink source files
BuildMavLink()
#AirLib source files
BuildAirlib()
#AirsimWrapper source files
BuildAirsimWrapper()


###################### Link source files to library ######################################
if (${APPLE})
    add_library(
        ${PROJECT_NAME} MODULE
        ${RPC_LIBRARY_SOURCE_FILES}
        ${MAVLINK_LIBRARY_SOURCE_FILES}
        ${AIRLIB_LIBRARY_SOURCE_FILES}
        ${AIRSIMWRAPPER_LIBRARY_SOURCE_FILES}
    )

    set_target_properties(${PROJECT_NAME} PROPERTIES BUNDLE TRUE)
else ()
    add_library(
        ${PROJECT_NAME} SHARED
        ${RPC_LIBRARY_SOURCE_FILES}
        ${MAVLINK_LIBRARY_SOURCE_FILES}
        ${AIRLIB_LIBRARY_SOURCE_FILES}
        ${AIRSIMWRAPPER_LIBRARY_SOURCE_FILES}
    )
endif ()

target_link_libraries(${PROJECT_NAME} ${CMAKE_THREAD_LIBS_INIT}  -lstdc++ -lpthread -lboost_filesystem)



##################### Build Options #############################3
# Rpc
RpcCheckMSVN()
RpcCmakePkg()
RpcMSVNConfig()

1

There are 1 best solutions below

0
On BEST ANSWER

You have told your library target to link against boost_filesystem, but you did not convey in your CMake where to find the Boost header files.

The idiomatic way to find Boost using CMake is to use the configuration files that now ship with Boost (e.g. BoostConfig.cmake), as of Boost version 1.70 and greater. You can make use of these by calling find_package(Boost ...), then linking with the imported target Boost::filesystem:

# Tell CMake to locate Boost on your machine, specifically
# looking for the filesystem library.
find_package(Boost REQUIRED COMPONENTS filesystem)

...
# Link the Boost::filesystem target, which includes the Boost headers.
target_link_libraries(${PROJECT_NAME} PUBLIC
    ${CMAKE_THREAD_LIBS_INIT} 
    -lstdc++ 
    -lpthread 
    Boost::filesystem
)

This will pull in the Boost headers as well, so you don't need an explicit call to target_include_directories() to specify where the Boost headers are.


Note: To ensure the headers are installed on your system, you may need to install boost-devel, in addition to your boost installation.