我有一个在 Xcode 5 上运行的 boost.log 的非常小的示例项目,它是这样的:
#include <iostream>
#include <boost/log/core.hpp>
#include <boost/log/trivial.hpp>
#include <boost/log/expressions.hpp>
#include <boost/log/sinks/text_file_backend.hpp>
#include <boost/log/utility/setup/file.hpp>
#include <boost/log/utility/setup/common_attributes.hpp>
#include <boost/log/sources/severity_logger.hpp>
#include <boost/log/sources/record_ostream.hpp>
#include <boost/log/expressions/formatters/date_time.hpp>
#include <boost/log/support/date_time.hpp>
#include <boost/date_time/posix_time/posix_time_types.hpp>
#include <boost/log/utility/setup/console.hpp>
namespace logging = boost::log;
namespace keywords = boost::log::keywords;
namespace src = boost::log::sources;
namespace expr = boost::log::expressions;
int main(int argc, const char *argv[])
{
logging::add_file_log
(
keywords::file_name = "Out_%N.log",
keywords::format =
(
expr::stream
<< expr::format_date_time< boost::posix_time::ptime >("TimeStamp", "%Y-%m-%d %H:%M:%S")
<< ": [" << logging::trivial::severity
<< "] " << expr::smessage
)
);
logging::core::get()->set_filter(logging::trivial::severity >= logging::trivial::debug);
logging::add_common_attributes();
src::severity_logger< logging::trivial::severity_level > logger;
BOOST_LOG_SEV(logger, logging::trivial::warning) << "a warning message";
return 0;
}
现在命令行项目一切正常。
但是,一旦我在带有默认 Xcode 预编译头文件的真实项目中使用片段,我就会在 boost/type_traits/detail/has_binary_operator.hpp
和 中收到编译器错误>boost/lexical_cast.hpp
。
预编译 header test_prefix.pch
:
//
// Prefix header for all source files in project
//
#include <Carbon/Carbon.h>
已经浪费了数小时在 Xcode 中摆弄编译器设置和项目配置,因此欢迎任何反馈!
最佳答案
在您的前缀 header 中包含 Carbon/Carbon.h 之前,您可能需要#define __ASSERT_MACROS_DEFINE_VERSIONS_WITHOUT_UNDERSCORES 0
。参见 https://svn.boost.org/trac/boost/ticket/6219获取更多信息。
关于c++ - 使用 Xcode 预编译 header 时 boost.log 中断,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21414556/