Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Warnings when compiling Boost libraries in C++ Builder

I am getting warnings when I am trying to include <boost/thread.hpp> in C++ Builder. For every unit I am including it, C++ Builder shows up these 2 lines:

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.

This is Boost 1.39.

like image 638
Henry Avatar asked Jan 14 '23 10:01

Henry


1 Answers

add #define BOOST_THREAD_USE_LIB before including the thread.hpp.

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'.

This does a clean build and starts a thread properly.

like image 73
Gregor Brandt Avatar answered Jan 21 '23 17:01

Gregor Brandt