编译时出现如下错误:
对‘boost::json::value::operator=(char const*)’未定义的引用
对‘boost::json::value::destroy()’未定义的引用
对‘boost::json::object::operator[](boost::basic_string_view<char, std::char_traits<char> >)’未定义的引用
对‘boost::json::serializer::serializer()’未定义的引用
对‘boost::json::serializer::reset(boost::json::object const*)’未定义的引用
对‘boost::json::serializer::~serializer()’未定义的引用
对‘boost::json::object::~object()’未定义的引用
对‘boost::json::object::empty_’未定义的引用
对‘boost::json::serializer::read(char*, unsigned long)’未定义的引用
对‘boost::json::value::operator=(boost::json::object const&)’未定义的引用
使用版本:boost_1_77_0
默认编译boost,即使编译时追加了--with-libraries=all选项,编译出来的结果中没有libboost_json.so文件的
在boost官网上说明了,
https://www.boost.org/doc/libs/1_77_0/libs/json/doc/html/json/overview.html#json.overview.supported_compilers
1、在使用的文件中引入头文件方式,不需要依赖boost_json的动态库或静态库
To use as header-only; that is, to eliminate the requirement to link a program to a static or dynamic Boost.JSON library, simply place the following line in exactly one new or existing source file in your project.
#include <boost/json/src.hpp>
在此强调一下,因为src.hpp中包含了多个ipp文件;如果同一个工程下,include了多次src.hpp,会导致同一ipp文件生成了多个编译对象,当程序连接时,就会发生错误。
因此要保证一个应用程序只include一次src.hpp,如果要使用boost::json其中的接口,请#include "boost/json.hpp"
2、要生成独立的lib的方式(这个没有编译出来 :( ,不知道如何设置,有知道的大侠请留言)
Standalone Shared Library
To build a standalone shared library, it is necessary to define the macros BOOST_JSON_DECL and BOOST_JSON_CLASS_DECL as appropriate for your toolchain

本文介绍了解决Boost.JSON库在编译时出现未定义引用错误的方法。提供了两种解决方案:一是通过包含特定的头文件来消除链接时的依赖;二是尝试构建独立的共享库,但作者尚未成功实现。

715

被折叠的 条评论
为什么被折叠?



