简体   繁体   English

如何在 MacOS 上构建和链接 Boost.Serialization

[英]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.我正在使用 Boost 在 C++ 中构建客户端-服务器应用程序,我的一位同事正在 Ubuntu 中对服务器进行编码,他正在使用 Boost.Serialization 但我无法运行它,因为它找不到该库,此外我还需要客户端的库。 To build and link it to the project he's only created a CMAKE file like this:为了构建并将其链接到项目,他只创建了一个 CMAKE 文件,如下所示:

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.我正在使用 MacOS,我已经使用 Homebrew 安装了 Boost,并且我尝试按照 Boost 官方网站中的指南进行操作: https://www.boost.org/doc/libs/1_74_0/more/getting_started/unix- variables.html#prepare-to-use-a-boost-library-binary但我没有bootstrap.shb2 (指南中提到的命令)来构建库,我在互联网上到处搜索,仍然不知道如何进行。 Any help?有什么帮助吗?

Unfortunately, it seems that Homebrew only installs header libraries of Boost.不幸的是,Homebrew 似乎只安装了 Boost 的 header 库。 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:对我来说,安装所有内容的最简单方法是从他们的网站下载完整的 Boost 存档,然后按照此处的说明进行操作https://www.boost.org/doc/libs/1_74_0/more/getting_started/unix-variants.html #prepare-to-use-a-boost-library-binary然后将它们链接到 CMAKE 文件中,如下所示:

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.其中: prefix是您在使用./bootstrap.sh时使用--prefix标志指定的安装路径, libraries_needed是您需要用空格分隔的库列表,例如filesystem serializationProject_Name是您的项目,在 CMAKE 文件的project()命令中指定。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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