2011-11-24 83 views
3

MINGW 4.7.0升壓1.47
代碼:MINGW 4.7.0犯規編譯代碼用#include <升壓/線程>

#include <iostream> 
#include <boost/thread.hpp> 
int main(int argc, char *argv[]) 
{ 
std::cout<<"In main"<<std::endl; 
} 

編譯器串:

g++.exe -Wall -fexceptions -g -IC:\soft\ides_comp\mingw\include\boost_1_47_0 -c  D:\work\cpp_cb\mt1\main.cpp -o obj\Debug\main.o 

它不編譯和我有同樣的錯誤,無論我嘗試的編譯器選項。

警告:
In file included from C:\soft\ides_comp\mingw\include\boost_1_47_0/boost/thread/win32/thread_data.hpp:12:0, from C:\soft\ides_comp\mingw\include\boost_1_47_0/boost/thread/thread.hpp:15, from C:\soft\ides_comp\mingw\include\boost_1_47_0/boost/thread.hpp:13, from D:\work\cpp_cb\mt1\main.cpp:2: C:\soft\ides_comp\mingw\include\boost_1_47_0/boost/thread/win32/thread_heap_alloc.hpp:59:40: warning: inline function 'void* boost::detail::allocate_raw_heap_memory(unsigned int)' declared as dllimport: attribute ignored [-Wattributes] C:\soft\ides_comp\mingw\include\boost_1_47_0/boost/thread/win32/thread_heap_alloc.hpp:69:39: warning: inline function 'void boost::detail::free_raw_heap_memory(void*)' declared as dllimport: attribute ignored [-Wattributes]

錯誤:
In file included from C:\soft\ides_comp\mingw\include\boost_1_47_0/boost/smart_ptr/shared_ptr.hpp:30:0, from C:\soft\ides_comp\mingw\include\boost_1_47_0/boost/shared_ptr.hpp:17, from C:\soft\ides_comp\mingw\include\boost_1_47_0/boost/date_time/time_clock.hpp:17, from C:\soft\ides_comp\mingw\include\boost_1_47_0/boost/thread/thread_time.hpp:9, from C:\soft\ides_comp\mingw\include\boost_1_47_0/boost/thread/win32/thread_data.hpp:10, from C:\soft\ides_comp\mingw\include\boost_1_47_0/boost/thread/thread.hpp:15, from C:\soft\ides_comp\mingw\include\boost_1_47_0/boost/thread.hpp:13, from D:\work\cpp_cb\mt1\main.cpp:2:

C:\soft\ides_comp\mingw\include\boost_1_47_0/boost/checked_delete.hpp: In instantiation of 'void boost::checked_delete(T*) [with T = boost::error_info<boost::tag_original_exception_type, const std::type_info*>]':


C:\soft\ides_comp\mingw\include\boost_1_47_0/boost/smart_ptr/detail/shared_count.hpp:95:13: required from 'boost::detail::shared_count::shared_count(Y*) [with Y = boost::error_info<boost::tag_original_exception_type, const std::type_info*>]' C:\soft\ides_comp\mingw\include\boost_1_47_0/boost/smart_ptr/shared_ptr.hpp:183:50: required from 'boost::shared_ptr<T>::shared_ptr(Y*) [with Y = boost::error_info<boost::tag_original_exception_type, const std::type_info*>; T = boost::error_info<boost::tag_original_exception_type, const std::type_info*>]' C:\soft\ides_comp\mingw\include\boost_1_47_0/boost/exception/info.hpp:171:69: required from 'const E& boost::exception_detail::set_info(const E&, const boost::error_info<Tag, T>&) [with E = boost::unknown_exception; Tag = boost::tag_original_exception_type; T = const std::type_info*]' C:\soft\ides_comp\mingw\include\boost_1_47_0/boost/exception/info.hpp:192:46: required from 'typename boost::enable_if<boost::exception_detail::derives_boost_exception<E>, const E&>::type boost::operator<<(const E&, const boost::error_info<Tag, T>&) [with E = boost::unknown_exception; Tag = boost::tag_original_exception_type; T = const std::type_info*; typename boost::enable_if<boost::exception_detail::derives_boost_exception<E>, const E&>::type = const boost::unknown_exception&]' C:\soft\ides_comp\mingw\include\boost_1_47_0/boost/exception/detail/exception_ptr.hpp:182:13: required from 'void boost::unknown_exception::add_original_type(const E&) [with E = std::exception]' C:\soft\ides_comp\mingw\include\boost_1_47_0/boost/exception/detail/exception_ptr.hpp:161:32: required from here

警告2:
C:\soft\ides_comp\mingw\include\boost_1_47_0/boost/checked_delete.hpp:34:5: warning: deleting object of polymorphic class type 'boost::error_info<boost::tag_original_exception_type, const std::type_info*>' which has non-virtual destructor might cause undefined behaviour [-Wdelete-non-virtual-dtor]

什麼可以嗎?由於

+0

什麼是MinGW 4.7.0?你的意思是MinGW GCC 4.7? – rubenvb

+0

是的,mingw32-4.7.0 – Alexander

+0

我在這裏猜測:'http://code.google。COM/P/MinGW的-建立/'。試試4.6.2,看看問題是否存在。 – rubenvb

回答

1

如果您使用Win32線程編譯線程庫,你可能需要

-DBOOST_USE_WINDOWS_H 
在你的編譯器標誌

。雖然我不認爲這是問題(我因爲不使用它而得到一組不同的錯誤),但你可以試一試。

+0

它does not幫助,但無論如何。 – Alexander

0

這個答案可能不是很直,但: 我確實使用g ++ 4.7.0 20111209,它支持線程。

#include <iostream> 
#include <thread> 

using namespace std; 

void foo() 
{ 
    cout << "Hello from thread\n"; 
} 

int main() 
{ 
    thread th1(foo); 
    th1.join(); 
    return 0; 
} 

在編譯過程中使用-std = C++ 11的選擇使用哪一個支持多線程

PS的最新標準: 提升1.48編譯我的電腦上使用MinGW 4.7.0給出了一個錯誤(當試圖使用boost :: thread): 線程支持不可用:它已被顯式禁用BOOST_DISABLE_THREADS 所以我想它在默認情況下被g ++ 4.7.0禁用(使用g ++ 4.6.2它不是)。

2

在稍後的升級版本中已修復此問題。查看此處:

https://svn.boost.org/trac/boost/ticket/6165

更新升壓/配置/ STDLIB/libstdcpp3.hpp:

#if defined(_GLIBCXX_HAVE_GTHR_DEFAULT) \ 
    || defined(_GLIBCXX_HAS_GTHREADS) \ 
    || defined(_GLIBCXX__PTHREADS) \ 
    || defined(WIN32) 

增加_GLIBCXX_HAS_GTHREADS和/或WIN32(從上面的鏈接,看到補丁)。

WIN32似乎有點蠻力,但沒有工作沒有(至少不是對我來說,我使用舊的升壓版本1.42)。