I want to include Boost Beast into my project. It's a header-only library. I have cloned the Beast repository into the same directory as my project.
I am using the following in CMake to include the header:
set(BEAST_INCLUDE_DIR ../beast/include)
include_directories(${BEAST_INCLUDE_DIR})
set(SOURCE_FILES ${BEAST_INCLUDE_DIR}/boost/beast.hpp ...)
add_library(my_lib ${SOURCE_FILES})
I'm including using the following (alongside other Boost includes):
#include <boost/beast.hpp>
#include <boost/asio/io_service.hpp>
But I get the following error:
fatal error: boost/beast.hpp: No such file or directory
Do I need to do something special to include another "boost" directory? The path of the header is:
beast/include/boost/beast.hpp
I would suggest creating an interface library for Beast which you can then add as a dependency to your library.
Create interface library for Beast:
add_library(boost_beast INTERFACE)
target_include_directories(boost_beast
SYSTEM
PUBLIC
"${CMAKE_CURRENT_LIST_DIR}/../beast/include")
Note in the call to target_include_directories
I've specified:
SYSTEM
: tells the compiler the directories are meant as system include directories PUBLIC
: tells the compiler the directories should be made visible to both the target itself ( boost_beast
) and the users of the target (your library) Add Beast as a dependency to your library:
Then you can add boost_beast
as a dependency to your library:
add_library(my_lib ${SOURCE_FILES})
target_link_libraries(my_lib boost_beast)
At this point, my_lib
will transitively have the Boost Beast include directory available to it.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.