2013-05-08 108 views
4

我在嘗試在C++ Builder中包含<boost/thread.hpp>時收到警告。對於我包含它的每個單元,C++ Builder顯示了這2行:在C++ Builder中編譯Boost庫時的警告

thread_heap_alloc.hpp(59): W8128 Can't import a function being defined 
thread_heap_alloc.hpp(69): W8128 Can't import a function being defined 

已經嘗試了一些東西,但沒有工作。

它編譯正確,但是,它正在我的神經上。爲什麼顯示此消息?

的線是:

#include <boost/config/abi_prefix.hpp> 

namespace boost 
{ 
    namespace detail 
    { 
     inline BOOST_THREAD_DECL void* allocate_raw_heap_memory(unsigned size) 
     { 
      void* const eap_memory=detail::win32::HeapAlloc(detail::win32::GetProcessHeap(),0,size); 
      if(!heap_memory) 
      { 
       throw std::bad_alloc(); 
      } 
     return heap_memory; 
    } 

    inline BOOST_THREAD_DECL void free_raw_heap_memory(void* heap_memory) 
    { 
     BOOST_VERIFY(detail::win32::HeapFree(detail::win32::GetProcessHeap(),0,heap_memory)!=0); 
    } 

其中59是BOOST_THREAD_DECL低於{,由於是69看起來像BOOST_THREAD_DECL定義不正確或錯誤定義,試圖通過升壓代碼遵循不說簡單。

這是升壓1.39。

+0

你用什麼版本的Boost?你在'thread_heap_alloc.hpp'的上面幾行看到了什麼? – 2013-05-08 16:45:16

+0

我正在使用XE4。這是發生錯誤的文件:http://www.xup.in/dl,47109567/thread_heap_alloc.txt/ – Henry 2013-05-08 19:02:23

+0

如果您使用Boost 1.53,該怎麼辦? 1.39於4年零7天前發佈... – kennytm 2013-05-08 19:11:39

回答

7

在包含thread.hpp之前添加#define BOOST_THREAD_USE_LIB。

這是我測試:

#define BOOST_THREAD_USE_LIB 
extern "C" 
{ 
    namespace boost 
    { 
     void tss_cleanup_implemented(void) 
     { 
     /* 
     This function's sole purpose is to cause a link error in cases where 
     automatic tss cleanup is not implemented by Boost.Threads as a 
     reminder that user code is responsible for calling the necessary 
     functions at the appropriate times (and for implementing an a 
     tss_cleanup_implemented() function to eliminate the linker's 
     missing symbol error). 

     If Boost.Threads later implements automatic tss cleanup in cases 
     where it currently doesn't (which is the plan), the duplicate 
     symbol error will warn the user that their custom solution is no 
     longer needed and can be removed.*/ 
     } 
    } 
} 
#include <boost/thread.hpp> 

然後設置「使用動態RTL鏈接」和「鏈接與運行時包」。

這是乾淨的構建並正確啓動線程。

我寫這個博客條目:http://blog.marionette.ca/cross-platform-threading-for-c-builder-using-boostthread/

+0

謝謝,這幾乎解決了它:) – Henry 2013-05-08 20:54:53

+1

我發現了一些有趣的背景,這個問題,建議不要粗心實施tss_cleanup_implemented:https://forums.embarcadero。 COM/thread.jspa?MESSAGEID = 778808#778808 – 2016-02-09 08:15:29