【问题标题】:Warnings when compiling Boost libraries in C++ Builder在 C++ Builder 中编译 Boost 库时的警告
【发布时间】:2013-05-08 15:00:07
【问题描述】:

当我尝试在 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。

【问题讨论】:

  • 您使用什么版本的 Boost?您在thread_heap_alloc.hpp 的上述行中看到了什么?
  • 我正在使用 XE4。这是发生错误的文件:xup.in/dl,47109567/thread_heap_alloc.txt
  • 如果你使用 Boost 1.53 会怎样? 1.39 发布 4 年 7 天前...
  • 感谢提示,一定要试试。虽然 Embarcadero 提供了 1.39 的预装..
  • @KennyTM 1.53 不是 Embarcadero 的 32 位编译器的选项,只有 64 位。我们被困在 1.39

标签: c++ boost c++builder


【解决方案1】:

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

这会进行干净的构建并正确启动线程。

【讨论】:

  • 我发现了一些关于这个问题的有趣背景,建议不要随便实现 tss_cleanup_implemented:forums.embarcadero.com/thread.jspa?messageID=778808#778808
  • @Gregor Brandt 博客文章的链接似乎已损坏,您能修复它吗?
  • @RadiumZheng 抱歉,博客现在已关闭。我打算在圣诞节前把它弄回来。我会修改我的答案。
  • @Gregor Brandt 有没有机会让该博客启动并运行??
  • 博客在可预见的将来会关闭,抱歉。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-03-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-09-15
相关资源
最近更新 更多