2010-09-20 68 views
3

在我的項目中,我最近決定使用boost :: thread。我的代碼編譯Linux下的罰款,但Windows(x86或x64)下,我得到的gcc 4.5以下警告:如何使用gcc抑制boost :: thread警告?

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. 

我只是包括在我自己的.cpp文件,沒有什麼特別的<boost/thread.hpp>

因爲我無法控制boost的代碼,有沒有辦法來暫時禁止這些警告?例如:

#super_killing_macro_that_disable_some_warnings 
#include <boost/thread.hpp> 
#its_all_good_know_i_want_my_warnings_back 

我該怎麼辦?

+0

你在命令行中有'-Werror',你能把它拿出來嗎? – Anycorn 2010-09-20 07:14:28

+4

@aaa鯉魚:我想保留它。我希望我的代碼100%免費警告/錯誤。當然,我無法控制其他庫源代碼,所以在這種情況下,忽略是好的。 – ereOn 2010-09-20 07:16:00

+0

[如何從庫頭壓縮GCC警告?](http://stackoverflow.com/questions/1867065/how-to-suppress-gcc-warnings-from-library-headers) – dmckee 2011-11-16 18:45:52

回答

6

我剛剛發現-isystem選項,允許包括目錄爲系統目錄。目錄中沒有任何警告,因此它對我的任務似乎很完美。

此外,這具有使SCons忽略那些在依賴關係樹中的目錄的副作用。由於我不期望這些庫經常改變,所以沒關係。

+1

所做的只是停止警告,代碼仍然違反了嚴格的別名規則,可能會被錯誤編譯。使用'-fno-strict-aliasing'來告訴編譯器不要執行依賴規則後面代碼的優化。 – 2012-05-06 15:20:49

1

你可能有一些運氣診斷附註: http://gcc.gnu.org/onlinedocs/gcc/Diagnostic-Pragmas.html

+0

謝謝。但我不知道要關閉哪些標誌。我怎麼知道 ? – ereOn 2010-09-20 07:28:37

+0

@ereOn首先,嘗試'-Werror'和嚴格的別名標誌,我不記得確切的選項。 http://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html – Anycorn 2010-09-20 07:31:22

+0

警告來自'-Wstrict-aliasing'(正如Anycorn所說,當然你可以通過閱讀手冊找到)。如果使用'-fno-strict-aliasing'進行編譯,即使編譯器違反嚴格的別名規則,編譯器也不會錯誤編譯代碼,並且警告也會被抑制。 – 2012-05-06 15:16:25

1

我有在mingw-GET-INST-20101030安裝了GCC 4.5.0在Windows XP SP3幾乎是相同的警告與MinGW和促進1.45.0建成在此間表示

http://fw-geekycoder.blogspot.com/2010/12/building-boost-using-mingw.html

我我正在使用BOOST_THREAD_USE_LIB編譯器標誌和-lboost_thread-mgw45-mt-1_45鏈接器標誌。在這篇文章結尾處,我得到的僅有的四條警告如下。

C:\工作空間\ boost_1_45_0 /升壓/線程/的Win32/shared_mutex.hpp:113:103:從這裏實例 C:\工作空間\ boost_1_45_0 /升壓/線程/的Win32/shared_mutex.hpp:53:99:警告:解引用類型指針會破壞嚴格別名規則 C:\ workspace \ boost_1_45_0/boost/thread/win32/shared_mutex.hpp:53:99:警告:解引用類型指針會破壞嚴格別名規則 C :\ workspace \ boost_1_45_0/boost/thread/win32/shared_mutex.hpp:54:52:warning:取消引用類型化指針將打破嚴格別名規則 C:\ workspace \ boost_1_45_0/boost/thread/win32/shared_mutex.hpp :54:52:warning:解引用類型指針會打破嚴格別名規則

我還沒有能夠讓結果代碼不會崩潰,所以我不知道這些警告是否重要(通過檢查線程是否改變我的數值結果)。