gpt4 book ai didi

c++ - 让 Boost asio 工作

转载 作者:行者123 更新时间:2023-11-28 00:46:40 26 4
gpt4 key购买 nike

我正在尝试将 Boost asio 库用于套接字。

我使用自制软件安装了 boost brew install boost

构建后我尝试了 the tutorial用于在 boost 的网站上创建服务器。

我所做的只是将该代码粘贴到名为 main.cc 的文件中

当我尝试编译 g++ main.cc 时出现此错误:

Undefined symbols for architecture x86_64:
"boost::system::system_category()", referenced from:
__static_initialization_and_destruction_0(int, int)in ccTbzxpk.o
boost::asio::error::get_system_category() in ccTbzxpk.o
boost::system::error_code::error_code()in ccTbzxpk.o
"boost::system::generic_category()", referenced from:
__static_initialization_and_destruction_0(int, int)in ccTbzxpk.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status

出了什么问题?

最佳答案

那些是链接器错误。如果您阅读 docs :

The following libraries must be available in order to link programs that use Boost.Asio:

Boost.System for the boost::system::error_code and boost::system::system_error classes. Boost.Regex (optional) if you use any of the read_until() or async_read_until() overloads that take a boost::regex parameter. OpenSSL (optional) if you use Boost.Asio's SSL support.

Furthermore, some of the examples also require the Boost.Thread, Boost.Date_Time or Boost.Serialization libraries.

现在,你发布的错误都说:boost::system,这意味着你需要像这样链接(假设一切都是默认的):g++ main.cc -lboost_system

请阅读What do 'statically linked' and 'dynamically linked' mean?有关链接的深入信息。

关于c++ - 让 Boost asio 工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15981132/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com