【问题标题】:Can't compile against Boost.log on OS X无法在 OS X 上针对 Boost.log 进行编译
【发布时间】:2011-07-04 15:29:30
【问题描述】:

我正在尝试构建和运行 Boost.log 的教程示例,并遇到编译器错误,这让我很困惑,需要一些帮助。基本细节;我已经在 OS X 上构建了包含 boost.log 的 boost,但是当我尝试编译任何教程示例时,我从 boost 日志的 'trivial.hpp' 包含文件中得到一个重载的 'operator>>' 错误。

错误报告在

log/utility/explicit_operator_bool.hpp

这是堆栈:

/usr/local/include/boost/log/utility/explicit_operator_bool.hpp:67:29: error: overloaded 'operator>>' must have at least one parameter of class or enumeration type [2]
In file included from /usr/local/include/boost/log/attributes/attribute_name.hpp:27:
In file included from /usr/local/include/boost/log/attributes/attribute_set.hpp:28:
In file included from /usr/local/include/boost/log/sources/basic_logger.hpp:37:
In file included from /usr/local/include/boost/log/sources/severity_logger.hpp:27:
In file included from /usr/local/include/boost/log/trivial.hpp:25:
In file included from /Volumes/Macintosh HD 2/code/Logging Tut   1/loggingTut1/loggingTut1/main.cpp:18:
Overloaded 'operator>>' must have at least one parameter of class or enumeration type in /usr/local/include/boost/log/utility/explicit_operator_bool.hpp

环顾四周,看看是否有其他人有类似的情况,但我一无所获 - 谁能解释我错过了什么或问题可能是什么?

详情:

我正在使用 Xcode 4.0.2 在 OS X (10.6.8) 上尝试这个

我已经下载并构建了 1_46_1 boost 版本,它适用于我的主要基于 boost 的项目(使用 Boost Asio、boost 线程等)。

Boost.log 还没有在主版本中,所以我从 sourceforge 下载了它,就像这个问题一样: boost-log-how-to-get-it-and-how-to-build-it

我将下载的分支中的boost/log目录复制到boost_1_46_1/boost/log目录中,将libs/log目录复制到boost_1_46_1/libs/log

我从/usr/local/include/boost/usr/local/lib 中删除了所有增强功能,然后使用以下命令重新构建:

./bootstrap.sh --with-libraries=all --prefix=/usr/local --includedir=/usr/local/include --libdir=/usr/local/lib

紧随其后

sudo ./bjam install > build.log

我检查了输出是否有错误,它看起来很干净 - 没有任何报告。我在/usr/local 下拥有所有的 boost 库和头文件。我检查了我的 Asio 项目,并且在这个版本中一切正常(没有提升日志)。我为日志教程创建了一个新项目,设置了库路径和包含路径,并将 lboost_log 添加到链接器选项中。

在尝试使用 Boost 日志的教程程序时会出现问题 - 如 Boost Log 文档 here 或 svn here 文件中包含的示例中所述

来自 SVN 的示例如下所示:

/*
 *          Copyright Andrey Semashev 2007 - 2011.
 * Distributed under the Boost Software License, Version 1.0.
 *    (See accompanying file LICENSE_1_0.txt or copy at
 *          http://www.boost.org/LICENSE_1_0.txt)
 */
/*!
 * \file   main.cpp
 * \author Andrey Semashev
 * \date   07.11.2009
 *
 * \brief  An example of trivial logging.
 */

// #define BOOST_ALL_DYN_LINK 1
// #define BOOST_LOG_DYN_LINK 1

#include <boost/log/trivial.hpp>
#include <boost/log/core.hpp>
#include <boost/log/filters.hpp>

int main(int argc, char* argv[])
{
    // Trivial logging: all log records are written into a file
    BOOST_LOG_TRIVIAL(trace) << "A trace severity message";
    BOOST_LOG_TRIVIAL(debug) << "A debug severity message";
    BOOST_LOG_TRIVIAL(info) << "An informational severity message";
    BOOST_LOG_TRIVIAL(warning) << "A warning severity message";
    BOOST_LOG_TRIVIAL(error) << "An error severity message";
    BOOST_LOG_TRIVIAL(fatal) << "A fatal severity message";

    // Filtering may also be applied
    using namespace boost::log;

    core::get()->set_filter
    (
        filters::attr< trivial::severity_level >("Severity") >= trivial::info
    );

    // Now the first two lines will not pass the filter
    BOOST_LOG_TRIVIAL(trace) << "A trace severity message";
    BOOST_LOG_TRIVIAL(debug) << "A debug severity message";
    BOOST_LOG_TRIVIAL(info) << "An informational severity message";
    BOOST_LOG_TRIVIAL(warning) << "A warning severity message";
    BOOST_LOG_TRIVIAL(error) << "An error severity message";
    BOOST_LOG_TRIVIAL(fatal) << "A fatal severity message";

    return 0;
}

当我构建代码时,出现两个错误:

语义问题 重载的 'operator>>' 必须至少有一个类或枚举类型的参数 语义问题 重载的 'operator

并且在来自 Boost Log 的文件 explicit_operator_bool.hpp 中报告了错误:

.
.
.
} // namespace boost

// These operators are not found through ADL
template< typename T > void operator<< (T const&,     boost::log::aux::unspecified_bool_type);
template< typename T > void operator>> (T const&, boost::log::aux::unspecified_bool_type);

#define BOOST_LOG_EXPLICIT_OPERATOR_BOOL()\
.
.
.

我在Xcode中得到的堆栈如下:

/usr/local/include/boost/log/utility/explicit_operator_bool.hpp:67:29: error: overloaded 'operator>>' must have at least one parameter of class or enumeration type [2]
In file included from /usr/local/include/boost/log/attributes/attribute_name.hpp:27:
In file included from /usr/local/include/boost/log/attributes/attribute_set.hpp:28:
In file included from /usr/local/include/boost/log/sources/basic_logger.hpp:37:
In file included from /usr/local/include/boost/log/sources/severity_logger.hpp:27:
In file included from /usr/local/include/boost/log/trivial.hpp:25:
In file included from /Volumes/Macintosh HD 2/code/Logging Tut   1/loggingTut1/loggingTut1/main.cpp:18:
Overloaded 'operator>>' must have at least one parameter of class or enumeration type in /usr/local/include/boost/log/utility/explicit_operator_bool.hpp

【问题讨论】:

  • boost::log 还不是受支持的 boost 库。因此,它不能在每个可以想象的平台和编译器上编译也就不足为奇了..

标签: c++ logging boost xcode4


【解决方案1】:

有点回答我自己的问题(因为它可能会帮助其他 Xcode/OSX 用户)。

查看explicit_operator.bool.hpp文件,里面有一些条件代码可以让我们通过设置绕过问题模板:

#define BOOST_LOG_NO_UNSPECIFIED_BOOL

教程然后为我编译和运行。

我不确定为什么需要这样做或下游可能会产生什么影响(请注意,像很多用户一样,我对获得轻量级日志框架的快速有效方法感兴趣,如果我们必须花时间研究框架的内部工作原理,这有点无效......)

正如评论所说,它还不是一个受支持的库,所以在这个阶段期望太多可能是不公平的。

克里斯

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-01-25
    • 1970-01-01
    • 2017-02-07
    • 2011-09-23
    • 2012-10-25
    • 1970-01-01
    相关资源
    最近更新 更多