在C ++ Builder中编译Boost库时的警告

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了在C ++ Builder中编译Boost库时的警告相关的知识,希望对你有一定的参考价值。

当我试图在C ++ Builder中包含<boost/thread.hpp>时,我收到警告。对于我所包含的每个单元,C ++ Builder显示这两行:

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没有正确定义或错误定义,试图通过Boost代码并不那么容易。

这是Boost 1.39。

答案

在包含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>

然后设置'Link with Dynamic RTL'和'Link with Runtime Packages'。

这样做是一个干净的构建并正确启动一个线程。

博客目前已关闭,但此链接将来有效(或编辑为有效,对不起)我为此写了一篇博客文章:http://blog.marionette.ca/cross-platform-threading-for-c-builder-using-boostthread/

以上是关于在C ++ Builder中编译Boost库时的警告的主要内容,如果未能解决你的问题,请参考以下文章

VS2010使用boost::geometry库时为什么编译不通过说明

在 C++Builder 中使用 boost::regex 提取双引号

Boost statechart - 使用状态图作为模板参数时的编译错误

VS2013编译64位boost

read()的Linux C

C ++ Builder:#include 错误