Open honey-speaks-tech opened 1 year ago
find_package(Boost 1.74.0 REQUIRED CONFIG)
add_library(my_lib)
target_include_directories(my_lib PUBLIC
${PROJECT_SOURCE_DIR}/src/common/state/
${PROJECT_SOURCE_DIR}/src/common/
${PROJECT_SOURCE_DIR}/src/config
)
target_sources(my_lib PRIVATE my_lib.cpp)
target_link_libraries(my_lib PUBLIC boost::boost)
this is how your CMakeLists.txt
file should look like. It seems the cci boost package doesnt provide an alias for the Boost::asio
target, even though the official boost release does.
you also have to use the proper conan generators, CMakeDeps
& CMakeToolchain
.
asio is header only, it's part of Boost::headers
(or Boost::boost
). Boost asio depends on boost system, but it's also header only since Boosy 1.69, so Boost::headers
should be sufficient. Don't use boost::boost
target, it's not an official target, it's created as a side effect of CMakeDeps
internal behavior, and actually it links everything instead of header only libs only.
What is your question?
Hi, I have a query regarding selectively integrating required boost libraries with our C++ project build using conan & cmake. For that, I tried the following, I will be pasting excerpts from relevant files. Please share your valuable thoughts on this and help me sort out this issue. I have more boost libaries needed in future in my C++ project, which I am planning to link whenever is required. Any help would be greatly appreciated.
Thank you in advance, Honey
Honey Sukesan
conanfile.py
requires = ( "rapidjson/1.1.0", "ms-gsl/4.0.0", "boost/1.74.0")
CMakelists.txt
find_package(Boost 1.74.0 REQUIRED system) add_library(my_lib)
target_include_directories( my_lib PUBLIC ${CMAKE_CURRENT_LIST_DIR} ${PROJECT_SOURCE_DIR}/src/common/state/ ${PROJECT_SOURCE_DIR}/src/common/ ${PROJECT_SOURCE_DIR}/src/config)
IF(Boost_FOUND) INCLUDE_DIRECTORIES(${Boost_INCLUDE_DIRS}) LINK_DIRECTORIES(${Boost_LIBRARY_DIRS}) ENDIF(Boost_FOUND)
target_sources(my_lib PRIVATE my_lib.cpp) target_link_libraries(my_lib PUBLIC ${Boost_LIBRARIES})
When I tried the above, I was getting a lot of errors in the build process, I am pasting excerpt from the error logs below:
/home/honey/.conan/data/boost/1.74.0/_/_/package/2033245bf5a77efcda848373b0aa1e71cf9b4dc4/include/boost/asio/impl/read_until.hpp: In member function 'void boost::asio::detail::initiate_async_read_until_expr_v2<AsyncReadStream>::operator()(ReadHandler&&, DynamicBuffer_v2&&, const RegEx&) const': /home/honey/.conan/data/boost/1.74.0/_/_/package/2033245bf5a77efcda848373b0aa1e71cf9b4dc4/include/boost/asio/detail/handler_type_requirements.hpp:172:41: error: conversion from 'long unsigned int' to 'int' may change value [-Werror=conversion] 169 | sizeof( \ | ~~~~~~~~~ 170 | boost::asio::detail::argbyv( \ | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 171 | boost::asio::detail::rvref< \ | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 172 | asio_true_handler_type>())) + \ | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~ 173 | sizeof( \ | ~~~~~~~~~ 174 | boost::asio::detail::lvref< \ | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 175 | asio_true_handler_type>()( \ | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 176 | boost::asio::detail::lvref<const boost::system::error_code>(), \ | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 177 | boost::asio::detail::lvref<const std::size_t>()), \ | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 178 | char(0))> BOOST_ASIO_UNUSED_TYPEDEF | ~~~~~~~~ /home/honey/.conan/data/boost/1.74.0/_/_/package/2033245bf5a77efcda848373b0aa1e71cf9b4dc4/include/boost/asio/impl/read_until.hpp:2938:7: note: in expansion of macro 'BOOST_ASIO_READ_HANDLER_CHECK' 2938 | BOOST_ASIO_READ_HANDLER_CHECK(ReadHandler, handler) type_check; | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /home/honey/.conan/data/boost/1.74.0/_/_/package/2033245bf5a77efcda848373b0aa1e71cf9b4dc4/include/boost/asio/impl/read_until.hpp: In member function 'void boost::asio::detail::initiate_async_read_until_match_v2<AsyncReadStream>::operator()(ReadHandler&&, DynamicBuffer_v2&&, MatchCondition) const': /home/honey/.conan/data/boost/1.74.0/_/_/package/2033245bf5a77efcda848373b0aa1e71cf9b4dc4/include/boost/asio/detail/handler_type_requirements.hpp:172:41: error: conversion from 'long unsigned int' to 'int' may change value [-Werror=conversion] 169 | sizeof( \ | ~~~~~~~~~ 170 | boost::asio::detail::argbyv( \ | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 171 | boost::asio::detail::rvref< \ | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 172 | asio_true_handler_type>())) + \ | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~ 173 | sizeof( \ | ~~~~~~~~~ 174 | boost::asio::detail::lvref< \ | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 175 | asio_true_handler_type>()( \ | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 176 | boost::asio::detail::lvref<const boost::system::error_code>(), \ | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 177 | boost::asio::detail::lvref<const std::size_t>()), \ | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 178 | char(0))> BOOST_ASIO_UNUSED_TYPEDEF | ~~~~~~~~ /home/honey/.conan/data/boost/1.74.0/_/_/package/2033245bf5a77efcda848373b0aa1e71cf9b4dc4/include/boost/asio/impl/read_until.hpp:3255:7: note: in expansion of macro 'BOOST_ASIO_READ_HANDLER_CHECK' 3255 | BOOST_ASIO_READ_HANDLER_CHECK(ReadHandler, handler) type_check; | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /home/honey/.conan/data/boost/1.74.0/_/_/package/2033245bf5a77efcda848373b0aa1e71cf9b4dc4/include/boost/asio/impl/write_at.hpp: In member function 'void boost::asio::detail::initiate_async_write_at_buffer_sequence<AsyncRandomAccessWriteDevice>::operator()(WriteHandler&&, uint64_t, const ConstBufferSequence&, CompletionCondition&&) const': /home/honey/.conan/data/boost/1.74.0/_/_/package/2033245bf5a77efcda848373b0aa1e71cf9b4dc4/include/boost/asio/detail/handler_type_requirements.hpp:199:41: error: conversion from 'long unsigned int' to 'int' may change value [-Werror=conversion] 196 | sizeof( \ | ~~~~~~~~~ 197 | boost::asio::detail::argbyv( \ | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 198 | boost::asio::detail::rvref< \ | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 199 | asio_true_handler_type>())) + \ | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~ 200 | sizeof( \ | ~~~~~~~~~ 201 | boost::asio::detail::lvref< \ | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 202 | asio_true_handler_type>()( \ | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 203 | boost::asio::detail::lvref<const boost::system::error_code>(), \ | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 204 | boost::asio::detail::lvref<const std::size_t>()), \ | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 205 | char(0))> BOOST_ASIO_UNUSED_TYPEDEF | ~~~~~~~~ /home/honey/.conan/data/boost/1.74.0/_/_/package/2033245bf5a77efcda848373b0aa1e71cf9b4dc4/include/boost/asio/impl/write_at.hpp:356:7: note: in expansion of macro 'BOOST_ASIO_WRITE_HANDLER_CHECK' 356 | BOOST_ASIO_WRITE_HANDLER_CHECK(WriteHandler, handler) type_check; | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /home/honey/.conan/data/boost/1.74.0/_/_/package/2033245bf5a77efcda848373b0aa1e71cf9b4dc4/include/boost/asio/impl/write_at.hpp: In member function 'void boost::asio::detail::initiate_async_write_at_streambuf<AsyncRandomAccessWriteDevice>::operator()(WriteHandler&&, uint64_t, boost::asio::basic_streambuf<Allocator>*, CompletionCondition&&) const': /home/honey/.conan/data/boost/1.74.0/_/_/package/2033245bf5a77efcda848373b0aa1e71cf9b4dc4/include/boost/asio/detail/handler_type_requirements.hpp:199:41: error: conversion from 'long unsigned int' to 'int' may change value [-Werror=conversion] 196 | sizeof( \ | ~~~~~~~~~ 197 | boost::asio::detail::argbyv( \ | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 198 | boost::asio::detail::rvref< \ | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 199 | asio_true_handler_type>())) + \ | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~ 200 | sizeof( \ | ~~~~~~~~~ 201 | boost::asio::detail::lvref< \ | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 202 | asio_true_handler_type>()( \ | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 203 | boost::asio::detail::lvref<const boost::system::error_code>(), \ | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 204 | boost::asio::detail::lvref<const std::size_t>()), \ | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 205 | char(0))> BOOST_ASIO_UNUSED_TYPEDEF | ~~~~~~~~ /home/honey/.conan/data/boost/1.74.0/_/_/package/2033245bf5a77efcda848373b0aa1e71cf9b4dc4/include/boost/asio/impl/write_at.hpp:576:7: note: in expansion of macro 'BOOST_ASIO_WRITE_HANDLER_CHECK' 576 | BOOST_ASIO_WRITE_HANDLER_CHECK(WriteHandler, handler) type_check; | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ In file included from /home/honey/.conan/data/boost/1.74.0/_/_/package/2033245bf5a77efcda848373b0aa1e71cf9b4dc4/include/boost/date_time/posix_time/posix_time_types.hpp:11, from /home/honey/.conan/data/boost/1.74.0/_/_/package/2033245bf5a77efcda848373b0aa1e71cf9b4dc4/include/boost/asio/time_traits.hpp:23, from /home/honey/.conan/data/boost/1.74.0/_/_/package/2033245bf5a77efcda848373b0aa1e71cf9b4dc4/include/boost/asio/detail/timer_queue_ptime.hpp:22, from /home/honey/.conan/data/boost/1.74.0/_/_/package/2033245bf5a77efcda848373b0aa1e71cf9b4dc4/include/boost/asio/detail/deadline_timer_service.hpp:29, from /home/honey/.conan/data/boost/1.74.0/_/_/package/2033245bf5a77efcda848373b0aa1e71cf9b4dc4/include/boost/asio/basic_deadline_timer.hpp:25, from /home/honey/.conan/data/boost/1.74.0/_/_/package/2033245bf5a77efcda848373b0aa1e71cf9b4dc4/include/boost/asio.hpp:25, ..... /home/honey/.conan/data/boost/1.74.0/_/_/package/2033245bf5a77efcda848373b0aa1e71cf9b4dc4/include/boost/date_time/microsec_time_clock.hpp: In instantiation of 'static time_type boost::date_time::microsec_clock<time_type>::create_time(boost::date_time::microsec_clock<time_type>::time_converter) [with time_type = boost::posix_time::ptime; boost::date_time::microsec_clock<time_type>::time_converter = tm* (*)(const long int*, tm*); time_t = long int]': /home/honey/.conan/data/boost/1.74.0/_/_/package/2033245bf5a77efcda848373b0aa1e71cf9b4dc4/include/boost/date_time/microsec_time_clock.hpp:78:25: required from 'static time_type boost::date_time::microsec_clock<time_type>::universal_time() [with time_type = boost::posix_time::ptime]' /home/honey/.conan/data/boost/1.74.0/_/_/package/2033245bf5a77efcda848373b0aa1e71cf9b4dc4/include/boost/asio/time_traits.hpp:48:47: required from here /home/honey/.conan/data/boost/1.74.0/_/_/package/2033245bf5a77efcda848373b0aa1e71cf9b4dc4/include/boost/date_time/microsec_time_clock.hpp:88:36: error: conversion from '__suseconds_t' {aka 'long int'} to 'uint32_t' {aka 'unsigned int'} may change value [-Werror=conversion] 88 | boost::uint32_t sub_sec = tv.tv_usec; | ~~~^~~~~~~ cc1plus: all warnings being treated as errors