簡體   English   中英

在 C++ Builder 中編譯 Boost 庫時的警告

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

當我嘗試在 C++ Builder 中包含<boost/thread.hpp>時收到警告。 對於我包含的每個單元,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

已經嘗試了一些東西,但沒有任何效果。

它編譯正確,但是,它讓我很緊張。 為什么會顯示此消息?

這些行是:

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

這會進行干凈的構建並正確啟動線程。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM