简体   繁体   中英

How to build and link Boost.Serialization on MacOS

I'm building a client-server application in C++ using Boost, a colleague of mine is coding the server in Ubuntu and he's using Boost.Serialization but I'm unable to run it because it doesn't find that library, besides I also need the library for the client. To build and link it to the project he's only created a CMAKE file like this:

cmake_minimum_required(VERSION 3.16)
project(RemoteBackup_Server)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_FLAGS "-pthread" )

add_executable(RemoteBackup_Server User.cpp main.cpp server.cpp server.h connection_handler.cpp connection_handler.h)


find_package(Boost REQUIRED COMPONENTS serialization filesystem)
include_directories(${Boost_INCLUDE_DIRS})
target_link_libraries(RemoteBackup_Server ${Boost_LIBRARIES})

Which compiles and links the library with no efforts. I'm using MacOS, I've installed Boost using Homebrew and I've tried to follow the guide in the Boost official site: https://www.boost.org/doc/libs/1_74_0/more/getting_started/unix-variants.html#prepare-to-use-a-boost-library-binary but I don't have bootstrap.sh and b2 (commands mentioned in the guide) to build the libraries and I've searched everywhere on the internet and still got no clue on how to proceed. Any help?

Unfortunately, it seems that Homebrew only installs header libraries of Boost. To me, the easiest way to install everything was downloading the complete Boost archive from their website and then follow the instructions from here https://www.boost.org/doc/libs/1_74_0/more/getting_started/unix-variants.html#prepare-to-use-a-boost-library-binary and then link them in the CMAKE file as follows:

set(Boost_INCLUDE_DIR prefix/include)
set(Boost_LIBRARY_DIR prefix/lib)
find_package(Boost COMPONENTS libraries_needed REQUIRED)
include_directories(${Boost_INCLUDE_DIR})
link_directories(${Boost_LIBRARY_DIR})
target_link_libraries(Project_Name ${Boost_LIBRARIES})

Where: prefix is the path of the installation that you specify with the --prefix flag when using ./bootstrap.sh , libraries_needed is the list of the libraries you need separated by a space, for example filesystem serialization , Project_Name is the name of your project, specified in the project() command in the CMAKE file.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM