c++ - 无法针对 OS X 上的 Boost.log 进行编译

标签 c++ logging boost xcode4

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

报错在

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 threads 等)。

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 中删除了所有 boost 内容,然后使用以下方法重新构建:

./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 项目,它对这个构建(没有 boost 日志)一切正常。我为日志教程创建了一个新项目,设置了库路径和包含路径,并将 lboost_log 添加到链接器选项。

尝试使用 Boost 日志的教程程序时会出现问题 - 如 Boost 日志文档中所述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

最佳答案

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

查看 explicit_operator.bool.hpp 文件,其中有一些条件代码允许我们通过设置绕过问题模板:

#define BOOST_LOG_NO_UNSPECIFIED_BOOL

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

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

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

克里斯

关于c++ - 无法针对 OS X 上的 Boost.log 进行编译,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6573436/

相关文章:

c++ - Bind() 在 Ubuntu 上失败,我做错了什么?

使用 nosetests.exe 的 Python 单元测试阻止使用日志记录模块登录文件

ruby-on-rails - 如何在 Rails 中记录 user_name?

c++ - 尝试在项目中包含 boost::thead 时未定义对 "__gx_personality_sj0"和其他引用

c++ - Boost::Spirit::QI 解析器:解析元素的索引

c++ - vb 整数到 c++ 到 ML32 到 c++ 到 vb UInteger

c++ - 在 Mac/Linux 上查找已安装的应用程序

C++重载+运算符不返回临时对象,为什么?

java - log4j spring jdbc异常

c++ - Code::Blocks 和 boost 1.55:存在动态库时不使用静态库