El uso de Boost.Log y Boost.ASIO provoca un locking

Estoy encontrando un problema donde el uso de Boost.Log en una aplicación provoca un locking o un locking cuando la aplicación carga una biblioteca compartida que utiliza Boost.ASIO! Cualquier apreciación sería apreciada; a continuación se muestra un ejemplo completo de comstackción cmake.

Si la statement del objeto del registrador global en main.cpp no ​​tiene comentarios, el progtwig o seg-falla inmediatamente o la llamada a la respuesta () no hará nada. Si se deja comentado, entonces el progtwig funciona.

Estoy usando Boost 1.55, g ++ (Ubuntu 4.8.4-2ubuntu1 ~ 14.04.3) 4.8.4

CMakeLists.txt

cmake_minimum_required (VERSION 2.8) project (boosttest) add_definitions(-fPIC -pthread -std=c++11) find_package(Boost 1.55.0 REQUIRED) add_definitions( -DBOOST_LOG_DYN_LINK ) include_directories(${Boost_INCLUDE_DIRS}) # Build the shared lib. add_library(testlib SHARED Lib ) target_link_libraries(testlib pthread ) # Build the test app. add_executable(testapp main ) target_link_libraries(testapp dl pthread boost_system boost_log ) 

Main.cpp

 #include  #include  #include  #include  #include  #include "Lib.h" using LoggerType = boost::log::sources::channel_logger_mt; //LoggerType gLogger; // If this is uncommented then probably a crash. std::unique_ptr LoadLib(const std::string& libName) { typedef Lib* (*LibConstructor)(); union FunctionLookup { LibConstructor entry; void* voidPtr; }; void* handle = ::dlopen(libName.c_str(), RTLD_LAZY); if (!handle) { throw std::runtime_error(::dlerror()); } FunctionLookup lookup; lookup.voidPtr = ::dlsym(handle, "create"); if (!lookup.voidPtr) { throw std::runtime_error(::dlerror()); } return std::unique_ptr(lookup.entry()); } int main(int argc, char* argv[]) { try { std::unique_ptr lib = LoadLib("./libtestlib.so"); std::cout <resolve("www.google.com"); } catch (const std::exception& e) { std::cerr << "*** " << e.what() << "\n"; } std::cout << "Exiting" << std::endl; return 0; } 

Lib.h

 #pragma once #include  using boost::asio::ip::tcp; class Lib { public: Lib(); virtual ~Lib() {} virtual void resolve(const std::string& host); private: void onResolve(const boost::system::error_code&, tcp::resolver::iterator); boost::asio::io_service m_ioService; tcp::resolver m_resolver; }; 

Lib.cpp

 #include  #include "Lib.h" extern "C" Lib* create() { return new Lib(); } extern "C" void destroy(Lib* lib) { delete lib; } Lib::Lib() : m_resolver(m_ioService) { } void Lib::resolve(const std::string& host) { tcp::resolver::query query(host, "http"); auto next = std::bind(&Lib::onResolve, this, std::placeholders::_1, std::placeholders::_2); m_resolver.async_resolve(query, std::move(next)); m_ioService.run(); // If it doesn't crash then this does nothing. } void Lib::onResolve(const boost::system::error_code& /*err*/, tcp::resolver::iterator /*iter*/) { std::cout << "onResolve() called!\n"; } 

Así que logré arreglar esto (creo) al no vincular dinámicamente las librerías Boost.Log.

Nuevo CMakeLists.txt

 cmake_minimum_required (VERSION 2.8) project (boosttest) add_definitions(-fPIC -pthread -std=c++11) find_package(Boost 1.55.0 REQUIRED) include_directories(${Boost_INCLUDE_DIRS}) # Build the shared lib. add_library(testlib SHARED Lib ) target_link_libraries(testlib pthread ) # Build the test app. add_executable(testapp main ) target_link_libraries(testapp dl pthread boost_system boost_log.a boost_thread )