C++ 如何使用gcc抑制boost::thread警告?

C++ 如何使用gcc抑制boost::thread警告?,c++,gcc,boost,warnings,suppress-warnings,C++,Gcc,Boost,Warnings,Suppress Warnings,在我的项目中,我最近决定使用boost::thread。我的代码在Linux下编译良好,但在Windows(x86或x64)下,gcc 4.5会出现以下警告: In file included from C:\Boost\include\boost-1_44/boost/thread/shared_mutex.hpp:14:0, from C:\Boost\include\boost-1_44/boost/thread/detail/thread_group.h

在我的项目中,我最近决定使用boost::thread。我的代码在Linux下编译良好,但在Windows(x86或x64)下,gcc 4.5会出现以下警告:

In file included from C:\Boost\include\boost-1_44/boost/thread/shared_mutex.hpp:14:0,
                 from C:\Boost\include\boost-1_44/boost/thread/detail/thread_group.hpp:9,
                 from C:\Boost\include\boost-1_44/boost/thread/thread.hpp:24,
                 from C:\Boost\include\boost-1_44/boost/thread.hpp:13,
                 from include\systools/upnp_control_point.hpp:50,
                 from src\upnp_control_point.cpp:45:
C:\Boost\include\boost-1_44/boost/thread/win32/shared_mutex.hpp: In member function 'T boost::shared_mutex::interlocked_
compare_exchange(T*, T, T) [with T = boost::shared_mutex::state_data]':
C:\Boost\include\boost-1_44/boost/thread/win32/shared_mutex.hpp:110:103:   instantiated from here
C:\Boost\include\boost-1_44/boost/thread/win32/shared_mutex.hpp:50:99: error: dereferencing type-punned pointer will bre
ak strict-aliasing rules
C:\Boost\include\boost-1_44/boost/thread/win32/shared_mutex.hpp:50:99: error: dereferencing type-punned pointer will bre
ak strict-aliasing rules
C:\Boost\include\boost-1_44/boost/thread/win32/shared_mutex.hpp:51:52: error: dereferencing type-punned pointer will bre
ak strict-aliasing rules
C:\Boost\include\boost-1_44/boost/thread/win32/shared_mutex.hpp:51:52: error: dereferencing type-punned pointer will bre
ak strict-aliasing rules
In file included from C:\Boost\include\boost-1_44/boost/algorithm/string/detail/find_format.hpp:18:0,
                 from C:\Boost\include\boost-1_44/boost/algorithm/string/find_format.hpp:23,
                 from C:\Boost\include\boost-1_44/boost/algorithm/string/replace.hpp:22,
                 from C:\Boost\include\boost-1_44/boost/date_time/date_facet.hpp:17,
                 from C:\Boost\include\boost-1_44/boost/date_time/gregorian/gregorian_io.hpp:16,
                 from C:\Boost\include\boost-1_44/boost/date_time/gregorian/gregorian.hpp:31,
                 from C:\Boost\include\boost-1_44/boost/date_time/posix_time/time_formatters.hpp:12,
                 from C:\Boost\include\boost-1_44/boost/date_time/posix_time/posix_time.hpp:24,
                 from include\systools/upnp_device.hpp:51,
                 from include\systools/upnp_control_point.hpp:48,
                 from src\upnp_control_point.cpp:45:
C:\Boost\include\boost-1_44/boost/algorithm/string/detail/find_format_store.hpp: At global scope:
C:\Boost\include\boost-1_44/boost/algorithm/string/detail/find_format_store.hpp: In instantiation of 'bool boost::algori
thm::detail::check_find_result(InputT&, FindResultT&) [with InputT = std::basic_string<char>, FindResultT = boost::itera
tor_range<__gnu_cxx::__normal_iterator<char*, std::basic_string<char> > >]':
C:\Boost\include\boost-1_44/boost/algorithm/string/detail/find_format_all.hpp:259:17:   instantiated from 'void boost::a
lgorithm::detail::find_format_all_impl(InputT&, FinderT, FormatterT, FindResultT) [with InputT = std::basic_string<char>
, FinderT = boost::algorithm::detail::first_finderF<const char*, boost::algorithm::is_equal>, FormatterT = boost::algori
thm::detail::const_formatF<boost::iterator_range<const char*> >, FindResultT = boost::iterator_range<__gnu_cxx::__normal
_iterator<char*, std::basic_string<char> > >]'
C:\Boost\include\boost-1_44/boost/algorithm/string/find_format.hpp:268:13:   instantiated from 'void boost::algorithm::f
ind_format_all(SequenceT&, FinderT, FormatterT) [with SequenceT = std::basic_string<char>, FinderT = boost::algorithm::d
etail::first_finderF<const char*, boost::algorithm::is_equal>, FormatterT = boost::algorithm::detail::const_formatF<boos
t::iterator_range<const char*> >]'
C:\Boost\include\boost-1_44/boost/algorithm/string/replace.hpp:654:13:   instantiated from 'void boost::algorithm::repla
ce_all(SequenceT&, const Range1T&, const Range2T&) [with SequenceT = std::basic_string<char>, Range1T = char [15], Range
2T = char [1]]'
C:\Boost\include\boost-1_44/boost/units/detail/utility.hpp:50:51:   instantiated from here
C:\Boost\include\boost-1_44/boost/algorithm/string/detail/find_format_store.hpp:74:18: error: unused parameter 'Input'
scons: *** [src\upnp_control_point.o] Error 1
scons: building terminated because of errors.

我能做些什么?

您可能会有一些诊断术语:

我刚刚发现了
-isystem
选项,该选项允许将目录作为系统目录。这些目录中的文件不会发出警告,因此它似乎非常适合我的任务


此外,这还有一个很好的副作用,就是让
SCons
忽略依赖关系树中的那些目录。因为我不希望这些库经常更改,所以这没关系。

我在Windows XP SP3上收到了几乎相同的警告,其中安装了MinGW-get-inst-20101030,GCC 4.5.0和boost 1.45.0,如图所示

我正在使用BOOST_THREAD_USE_LIB编译器标志和-lboost_THREAD-mgw45-mt-1_45链接器标志。我收到的四条警告如下

C:\workspace\boost\u 1\u 45\u 0/boost/thread/win32/shared\u mutex.hpp:113:103:从此处实例化 C:\workspace\boost\u 1\u 45\u 0/boost/thread/win32/shared\u mutex.hpp:53:99:警告:取消引用类型双关指针将破坏严格的别名规则 C:\workspace\boost\u 1\u 45\u 0/boost/thread/win32/shared\u mutex.hpp:53:99:警告:取消引用类型双关指针将破坏严格的别名规则 C:\workspace\boost\u 1\u 45\u 0/boost/thread/win32/shared\u mutex.hpp:54:52:警告:取消引用类型双关指针将破坏严格的别名规则 C:\workspace\boost\u 1\u 45\u 0/boost/thread/win32/shared\u mutex.hpp:54:52:警告:取消引用类型双关指针将破坏严格的别名规则


我还没能让生成的代码不崩溃,所以我不知道这些警告是否重要(通过检查线程是否会改变我的数值结果)。

你在命令行中有
-Werror
,你能把它取出来吗?@aaa carp:我想保留它。我希望我的代码100%没有警告/错误。当然,我无法控制其他库的源代码,所以在本例中,忽略是可以的。可能重复谢谢。但我不知道该关闭哪些标志。我怎么知道呢?@ereOn对于初学者,请尝试
-Werror
和严格的别名标志,我不记得确切的选项。该警告来自
-Wstrict aliasing
(正如Anycorn所说,您当然可以通过阅读手册找到)。如果使用
-fno strict aliasing
编译,即使违反了严格的别名规则,编译器也不会错误编译代码,警告也将被抑制。所做的只是停止警告,代码仍然违反了严格的别名规则,可能会被错误编译。使用
-fno strict aliasing
告诉编译器不要执行依赖于遵循规则的代码的优化。
#super_killing_macro_that_disable_some_warnings
#include <boost/thread.hpp>
#its_all_good_know_i_want_my_warnings_back