AirSim/Unity 在 macOS 上构建('boost/filesystem.hpp' 未找到文件)

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

我正在尝试在 MacOS Catalina 上安装 AirSim/Unity。当我 运行 Unity/build.sh 我得到一个致命错误:

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....

我已经用 brew 安装了 boost。这是我第一次使用 brew,所以我认为我需要编辑我的 CMakeList.txt。我尝试自己更改它,但没有成功。

我的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()

你已经告诉你的库目标 link 反对 boost_filesystem,但你没有在你的 CMake where 中找到 Boost header 文件。

使用 CMake 查找 Boost 的惯用方法是使用现在随 Boost 一起提供的配置文件(例如 BoostConfig.cmake),从 Boost 版本 1.70 及更高版本开始。您可以通过调用 find_package(Boost ...) 来使用这些,然后 link 使用导入的目标 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
)

这也会引入 Boost header,因此您不需要显式调用 target_include_directories() 来指定 Boost header 的位置。


注意:要确保 header 安装在您的系统上,除了 boost 安装之外,您可能还需要安装 boost-devel