Boost logo

Boost Interest :

Subject: [Boost-cmake] Adding Boost.Log to CMake Boost
From: Keith Laband (jeep1979_at_[hidden])
Date: 2012-11-19 13:55:36


I have tried adding Boost.Log to Cmake Boost. I am using CMake 2.8.8 and
the latest Boost.Log files from the trunk directory. It seems to build the
libraries okay, but when I try to link my program I get the following.

/media/data/workspace/mdxdev/tmp/staging/i686-mv-linux/usr/lib/libcls_utils.so:
undefined reference to
`boost::log_mt_posix::sinks::basic_text_file_backend<char>::construct(boost::filesystem2::basic_path<std::basic_string<char,
std::char_traits<char>, std::allocator<char> >,
boost::filesystem2::path_traits> const&, std::_Ios_Openmode, unsigned long
long, boost::function0<bool> const&, bool)'

------

libcls_utils.so is a wrapper around the Boost.Log libraries that I am
calling. The shareable library compiles and links. When my main program
goes to link, it get the libcls_utils.so, but can not resolve a symbol in
it. I believe I have traced it down to something I may have missed when
creating the CMakeLists.txt files. Here is a list of what I have. I used
the Jamfile.v2 created by bjam to figure out what to include in my
CMakeLists.txt file.

#
# Copyright Andrey Semashev 2007 - 2012.
# Distributed under the Boost Software License, Version 1.0.
# (See accompanying file LICENSE_1_0.txt or copy at
# http://www.boost.org/LICENSE_1_0.txt)
#

import os ;
import feature ;

lib psapi ;
lib ws2_32 ;

local rule default_logapi ( )
{
    local api = unix ;
    if [ os.name ] = "NT" { api = winnt ; }
    return $(api) ;
}

feature.feature logapi : unix winnt : propagated ;
feature.set-default logapi : [ default_logapi ] ;

project boost/log
    : source-location ../src
    : requirements
        <link>shared:<define>BOOST_LOG_DLL
        <logapi>unix:<define>BOOST_LOG_USE_NATIVE_SYSLOG=1
        <toolset>msvc:<define>_SCL_SECURE_NO_WARNINGS
        <toolset>msvc:<define>_SCL_SECURE_NO_DEPRECATE
        <toolset>msvc:<define>_CRT_SECURE_NO_WARNINGS
        <toolset>msvc:<define>_CRT_SECURE_NO_DEPRECATE
        <toolset>intel-win:<define>_SCL_SECURE_NO_WARNINGS
        <toolset>intel-win:<define>_SCL_SECURE_NO_DEPRECATE
        <toolset>intel-win:<define>_CRT_SECURE_NO_WARNINGS
        <toolset>intel-win:<define>_CRT_SECURE_NO_DEPRECATE
        <toolset>gcc:<cxxflags>-fno-strict-aliasing # avoids strict
aliasing violations in other Boost components
        <toolset>gcc-mingw:<linkflags>-Wl,--enable-auto-import
        <toolset>gcc-cygwin:<linkflags>-Wl,--enable-auto-import
        <library>/boost/date_time//boost_date_time
        <library>/boost/filesystem//boost_filesystem
        <library>/boost/system//boost_system
        <threading>single:<define>BOOST_LOG_NO_THREADS
        <threading>multi:<library>/boost/thread//boost_thread
    ;

DEPENDS event_log_backend.cpp : simple_event_log.mc ;

local BOOST_LOG_COMMON_SRC =
    attribute_name.cpp
    attribute_set.cpp
    attribute_values_view.cpp
    code_conversion.cpp
    core.cpp
    record_ostream.cpp
    severity_level.cpp
    global_logger_storage.cpp
    named_scope.cpp
    process_id.cpp
    thread_id.cpp
    timer.cpp
    exceptions.cpp
    default_sink.cpp
    text_ostream_backend.cpp
    text_file_backend.cpp
    syslog_backend.cpp
    thread_specific.cpp
    once_block.cpp
    timestamp.cpp
    threadsafe_queue.cpp
    event.cpp
    trivial.cpp
    ;

lib boost_log
    : ## sources ##
        $(BOOST_LOG_COMMON_SRC)
      ## winnt sources ##
        simple_event_log.mc
        event_log_backend.cpp
        debug_output_backend.cpp
        light_rw_mutex.cpp
        psapi
        ws2_32
    : ## requirements ##
        <define>BOOST_LOG_BUILDING_THE_LIB=1
        <define>BOOST_THREAD_DONT_USE_CHRONO=1 # Don't introduce false
dependency on Boost.Chrono
        <logapi>winnt
    ;

lib boost_log
    : ## sources ##
        $(BOOST_LOG_COMMON_SRC)
      ## unix sources ##
    : ## requirements ##
        <define>BOOST_LOG_BUILDING_THE_LIB=1
        <define>BOOST_THREAD_DONT_USE_CHRONO=1 # Don't introduce false
dependency on Boost.Chrono
        <logapi>unix
    ;

local BOOST_LOG_SETUP_COMMON_SRC =
    parser_utils.cpp
    init_from_stream.cpp
    init_from_settings.cpp
    filter_parser.cpp
    formatter_parser.cpp
    default_filter_factory.cpp
    ;

lib boost_log_setup
    : ## sources ##
        $(BOOST_LOG_SETUP_COMMON_SRC)
      ## winnt sources ##
        ws2_32
    : ## requirements ##
        <link>shared:<define>BOOST_LOG_SETUP_DLL
        <define>BOOST_LOG_SETUP_BUILDING_THE_LIB=1
        <define>BOOST_THREAD_DONT_USE_CHRONO=1 # Don't introduce false
dependency on Boost.Chrono
        <library>boost_log
        <logapi>winnt
    ;

lib boost_log_setup
    : ## sources ##
        $(BOOST_LOG_SETUP_COMMON_SRC)
      ## unix sources ##
    : ## requirements ##
        <link>shared:<define>BOOST_LOG_SETUP_DLL
        <define>BOOST_LOG_SETUP_BUILDING_THE_LIB=1
        <define>BOOST_THREAD_DONT_USE_CHRONO=1 # Don't introduce false
dependency on Boost.Chrono
        <library>boost_log
        <logapi>unix
    ;

------------------------------------

My Cmake file in the Log top level directory is

#
# Copyright Andrey Semashev 2007 - 2012.
# Distributed under the Boost Software License, Version 1.0.
# (See accompanying file LICENSE_1_0.txt or copy at
# http://www.boost.org/LICENSE_1_0.txt)
#

import os ;
import feature ;

lib psapi ;
lib ws2_32 ;

local rule default_logapi ( )
{
    local api = unix ;
    if [ os.name ] = "NT" { api = winnt ; }
    return $(api) ;
}

feature.feature logapi : unix winnt : propagated ;
feature.set-default logapi : [ default_logapi ] ;

project boost/log
    : source-location ../src
    : requirements
        <link>shared:<define>BOOST_LOG_DLL
        <logapi>unix:<define>BOOST_LOG_USE_NATIVE_SYSLOG=1
        <toolset>msvc:<define>_SCL_SECURE_NO_WARNINGS
        <toolset>msvc:<define>_SCL_SECURE_NO_DEPRECATE
        <toolset>msvc:<define>_CRT_SECURE_NO_WARNINGS
        <toolset>msvc:<define>_CRT_SECURE_NO_DEPRECATE
        <toolset>intel-win:<define>_SCL_SECURE_NO_WARNINGS
        <toolset>intel-win:<define>_SCL_SECURE_NO_DEPRECATE
        <toolset>intel-win:<define>_CRT_SECURE_NO_WARNINGS
        <toolset>intel-win:<define>_CRT_SECURE_NO_DEPRECATE
        <toolset>gcc:<cxxflags>-fno-strict-aliasing # avoids strict
aliasing violations in other Boost components
        <toolset>gcc-mingw:<linkflags>-Wl,--enable-auto-import
        <toolset>gcc-cygwin:<linkflags>-Wl,--enable-auto-import
        <library>/boost/date_time//boost_date_time
        <library>/boost/filesystem//boost_filesystem
        <library>/boost/system//boost_system
        <threading>single:<define>BOOST_LOG_NO_THREADS
        <threading>multi:<library>/boost/thread//boost_thread
    ;

DEPENDS event_log_backend.cpp : simple_event_log.mc ;

local BOOST_LOG_COMMON_SRC =
    attribute_name.cpp
    attribute_set.cpp
    attribute_values_view.cpp
    code_conversion.cpp
    core.cpp
    record_ostream.cpp
    severity_level.cpp
    global_logger_storage.cpp
    named_scope.cpp
    process_id.cpp
    thread_id.cpp
    timer.cpp
    exceptions.cpp
    default_sink.cpp
    text_ostream_backend.cpp
    text_file_backend.cpp
    syslog_backend.cpp
    thread_specific.cpp
    once_block.cpp
    timestamp.cpp
    threadsafe_queue.cpp
    event.cpp
    trivial.cpp
    ;

lib boost_log
    : ## sources ##
        $(BOOST_LOG_COMMON_SRC)
      ## winnt sources ##
        simple_event_log.mc
        event_log_backend.cpp
        debug_output_backend.cpp
        light_rw_mutex.cpp
        psapi
        ws2_32
    : ## requirements ##
        <define>BOOST_LOG_BUILDING_THE_LIB=1
        <define>BOOST_THREAD_DONT_USE_CHRONO=1 # Don't introduce false
dependency on Boost.Chrono
        <logapi>winnt
    ;

lib boost_log
    : ## sources ##
        $(BOOST_LOG_COMMON_SRC)
      ## unix sources ##
    : ## requirements ##
        <define>BOOST_LOG_BUILDING_THE_LIB=1
        <define>BOOST_THREAD_DONT_USE_CHRONO=1 # Don't introduce false
dependency on Boost.Chrono
        <logapi>unix
    ;

local BOOST_LOG_SETUP_COMMON_SRC =
    parser_utils.cpp
    init_from_stream.cpp
    init_from_settings.cpp
    filter_parser.cpp
    formatter_parser.cpp
    default_filter_factory.cpp
    ;

lib boost_log_setup
    : ## sources ##
        $(BOOST_LOG_SETUP_COMMON_SRC)
      ## winnt sources ##
        ws2_32
    : ## requirements ##
        <link>shared:<define>BOOST_LOG_SETUP_DLL
        <define>BOOST_LOG_SETUP_BUILDING_THE_LIB=1
        <define>BOOST_THREAD_DONT_USE_CHRONO=1 # Don't introduce false
dependency on Boost.Chrono
        <library>boost_log
        <logapi>winnt
    ;

lib boost_log_setup
    : ## sources ##
        $(BOOST_LOG_SETUP_COMMON_SRC)
      ## unix sources ##
    : ## requirements ##
        <link>shared:<define>BOOST_LOG_SETUP_DLL
        <define>BOOST_LOG_SETUP_BUILDING_THE_LIB=1
        <define>BOOST_THREAD_DONT_USE_CHRONO=1 # Don't introduce false
dependency on Boost.Chrono
        <library>boost_log
        <logapi>unix
    ;

------

And finally my CMakeList.txt file in the src directory is:

#
# Copyright Troy D. Straszheim
#
# Distributed under the Boost Software License, Version 1.0.
# See http://www.boost.org/LICENSE_1_0.txt
#

boost_add_library(log

  attribute_set.cpp
  attribute_values_view.cpp
  slim_string.cpp
  code_conversion.cpp
  core.cpp
  stream_provider.cpp
  severity_level.cpp
  global_logger_storage.cpp
  named_scope.cpp
  process_id.cpp
  timer.cpp
  exceptions.cpp
  sink_frontends.cpp
  text_ostream_backend.cpp
  text_file_backend.cpp
  syslog_backend.cpp
  thread_specific.cpp
  trivial.cpp

  SHARED_COMPILE_FLAGS -DBOOST_LOG_DYN_LINK=1
  SHARED_COMPILE_FLAGS -DBOOST_THREAD_DONT_USE_CHRONO=1
  )

boost_add_library(log_setup

  parser_utils.cpp
  init_from_stream.cpp
  init_from_settings.cpp
  filter_parser.cpp
  formatter_parser.cpp
  default_filter_factory.cpp

  SHARED_COMPILE_FLAGS -DBOOST_LOG_DYN_LINK=1
  SHARED_COMPILE_FLAGS -DBOOST_THREAD_DONT_USE_CHRONO=1
  )

----
Thanks for any help that may be rendered.
Keith


Boost-cmake list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk