2014-01-18 43 views
2

我遇到了與Boost相關的一個看似無法穿透的編譯錯誤,我將其簡化爲包含單個boost頭文件。在編制(與GCC 4.2在Mac OS X 10.6.8)僅包含這一個空文件包括:包含單次提升時的編譯錯誤posix_time.hpp頭

#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庫被用作「只有標題」 - 未建成。

任何線索?

+0

我假設你的意思是在編譯器集合中的GCC,而不是二進制文件,但只是在以下情況下:你用什麼命令來編譯?你是用'C++'還是'g ++',或者你真的使用'gcc'? – Corbin

+0

XCode正在生成:/Developer/use/bin/gcc-4.2 -x C++(加上所有其他選項,路徑等) – SMGreenfield

+0

我懷疑這個庫只是不喜歡GCC 4.2。 (它畢竟是相當古老的) –

回答

1

問題出在文件<AssertMacros.h>,它以某種方式被包括在內。

它定義了一個名爲check(和另一個名爲require)的宏,它與「boost/type_traits/detail/has_binary_operator.hpp」中名爲check的函數衝突。

您可以定義__ASSERTMACROS__以防止發生這種情況。

FWIW,在Mac OS X 10.7及更高版本中,Apple將這些宏重命名爲__check等,以防止此問題。

+0

- 你100%正確。 「不知何故」是10.5 SDK的CarbonCore.framework包含Debugging.h,後者又包含AssertMacros.h。是的,定義__ASSERTMACROS__解決了上述問題。有什麼其他的副作用呢? – SMGreenfield

+1

定義'__ASSERTMACROS__'可以有效地防止包含',因爲這就是它的'包含守護進程'。副作用是您不能使用該文件中定義的任何宏(您可能不會使用這些宏)。 –