包含单个boost posix_time.hpp标头时编译错误

时间:2014-01-18 22:42:54

标签: c++ gcc boost boost-date-time

我遇到了与Boost相关的看似难以理解的编译错误,我已将其简化为包含单个boost头文件。在编译时(在Mac OS X 10.6.8上使用GCC 4.2),仅包含此文件的空文件包括:

#include "boost/date_time/posix_time/posix_time.hpp"

...生成这些错误:

 In file included from ../../../Boost Libraries/Boost_1_55_0/boost/type_traits/has_left_shift.hpp:43,
                 from ../../../Boost Libraries/Boost_1_55_0/boost/lexical_cast.hpp:165,
                 from ../../../Boost Libraries/Boost_1_55_0/boost/date_time/string_parse_tree.hpp:13,
                 from ../../../Boost Libraries/Boost_1_55_0/boost/date_time/period_parser.hpp:14,
                 from ../../../Boost Libraries/Boost_1_55_0/boost/date_time/date_facet.hpp:23,
                 from ../../../Boost Libraries/Boost_1_55_0/boost/date_time/gregorian/gregorian_io.hpp:16,
                 from ../../../Boost Libraries/Boost_1_55_0/boost/date_time/gregorian/gregorian.hpp:31,
                 from ../../../Boost Libraries/Boost_1_55_0/boost/date_time/posix_time/time_formatters.hpp:12,
                 from ../../../Boost Libraries/Boost_1_55_0/boost/date_time/posix_time/posix_time.hpp:24,
                 from /Users/homedir/dev/TheProject/Mac/Xcode/../Source/feature/test.cpp:12:
../../../Boost Libraries/Boost_1_55_0/boost/type_traits/detail/has_binary_operator.hpp:155: error: expected unqualified-id before 'do'
In file included from ../../../Boost Libraries/Boost_1_55_0/boost/date_time/posix_time/posix_time.hpp:34,
                 from /Users/homedir/dev/TheProject/Mac/Xcode/../Source/feature/test.cpp:12:
../../../Boost Libraries/Boost_1_55_0/boost/date_time/posix_time/time_parsers.hpp:40: error: expected `}' at end of input
../../../Boost Libraries/Boost_1_55_0/boost/date_time/posix_time/time_parsers.hpp:40: error: expected unqualified-id at end of input
../../../Boost Libraries/Boost_1_55_0/boost/date_time/posix_time/time_parsers.hpp:40: error: expected `}' at end of input
../../../Boost Libraries/Boost_1_55_0/boost/date_time/posix_time/time_parsers.hpp:40: error: expected `}' at end of input
../../../Boost Libraries/Boost_1_55_0/boost/date_time/posix_time/time_parsers.hpp:40: error: expected `}' at end of input

这些Boost库被用作“仅标题” - 未构建。

任何线索?

1 个答案:

答案 0 :(得分:1)

问题出在文件<AssertMacros.h>中,它以某种方式被包含在内。

它定义了一个名为check的宏(和另一个名为require),它与“boost / type_traits / detail / has_binary_operator.hpp”中名为check的函数冲突。

您可以定义__ASSERTMACROS__以防止这种情况发生。

FWIW,在Mac OS X 10.7及更高版本中,Apple将这些宏重命名为__check等,以防止出现此问题。