2013-05-08 109 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