Search code examples
c++boostc++builderboost-threadc++builder-2010

Is it possible to compile boost::recursive_mutex statically in C++ Builder


boost::recursive_mutex and boost::lock_guard seem to use boost_thread-bcb-mt-1_39.dll in C++ Builder 2010. I see that there is also static version - boost_thread-bcb-mt-1_39.lib.

My code is something like this:

boost::recursive_mutex mylock;
//...
boost::lock_guard<boost::recursive_mutex> lock(mylock);

However, if I set compile option to Release and set Dynamic RTL option to False all I get is Mixing a dll boost library with a static runtime is a really bad idea.... Returning Dynamic RTL to True compiles but then it needs additional DLL's - cc32100mt.dll and boost_thread-bcb-mt-1_39.dll.

Is there a way to compile it statically in a single exe? After all, LIB file is provided, it should be possible. Is it a problem with this version of C++ Builder or Boost?


Solution

  • What I needed was to define in a header file:

    #define BOOST_THREAD_USE_LIB
    

    right before:

    #include <boost/thread/recursive_mutex.hpp>
    #include <boost/thread/locks.hpp>
    

    After then it compiles without any issues.