简体   繁体   English

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

[英]Warnings when compiling Boost libraries in C++ Builder

I am getting warnings when I am trying to include <boost/thread.hpp> in C++ Builder.当我尝试在 C++ Builder 中包含<boost/thread.hpp>时收到警告。 For every unit I am including it, C++ Builder shows up these 2 lines:对于我包含的每个单元,C++ Builder 会显示以下 2 行:

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

Already tried some things, nothing worked though.已经尝试了一些东西,但没有任何效果。

It compiles correctly, however, it's getting on my nerves.它编译正确,但是,它让我很紧张。 Why is this message being shown?为什么会显示此消息?

The lines are:这些行是:

#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);
    }

where 59 is the { below the BOOST_THREAD_DECL , as is 69. Looks like BOOST_THREAD_DECL is not defined properly or mis-defined, trying to follow through the Boost code is not that easy.其中 59 是BOOST_THREAD_DECL下方的{ ,和 69 一样。看起来BOOST_THREAD_DECL定义不正确或定义错误,尝试执行 Boost 代码并不是那么容易。

This is Boost 1.39.这是 Boost 1.39。

add #define BOOST_THREAD_USE_LIB before including the thread.hpp.在包含 thread.hpp 之前添加 #define BOOST_THREAD_USE_LIB。

This is what I tested:这是我测试的:

#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>

Then set 'Link with Dynamic RTL' and 'Link with Runtime Packages'.然后设置'Link with Dynamic RTL'和'Link with Runtime Packages'。

This does a clean build and starts a thread properly.这会进行干净的构建并正确启动线程。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM