Boost Log 1.65.1 Linking Issue

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

Boost Log 1.65.1 Linking Issue

Boost - Dev mailing list
Good morning,

I am trying to create a logger that uses Boost Log. I was successful
getting my code to compile with 1.63.0, so I know that I am not too far off
of the mark. cmake/make throws a linking issues whenever I attempt to
create a sink:

                typedef sinks::synchronous_sink<
sinks::text_ostream_backend > text_sink;
     boost::shared_ptr< text_sink > sink = boost::make_shared< text_sink
>();

or create file sink

logging::add_file_log
     (
keywords::file_name = log_specs.log_file,
keywords::rotation_size = 10 * 1024 * 1024,
keywords::time_based_rotation = sinks::file::rotation_at_time_point(0, 0,
0),
keywords::filter = min_severity || severity >= file_severity,
keywords::format =
(
     expr::stream
<< expr::format_date_time<boost::posix_time::ptime>("TimeStamp",
"%Y-%m-%d_%H:%M:%S.%f")
         << ": [" << severity << "]"
         << expr::smessage
),
keywords::auto_flush = true //flush to file..
     );

My code will compile 95% and then produce the following:

CMakeFiles/main.dir/src/Logger.cpp.o: In function
`boost::enable_if_c<(boost::log::v2_mt_posix::aux::is_character_type<wchar_t>::value&&boost::log::v2_mt_posix::aux::is_character_type<char>::value)&&((sizeof
(wchar_t))!=(sizeof (char))), bool>::type
boost::log::v2_mt_posix::aux::code_convert<wchar_t, char,
std::char_traits<char>, std::allocator<char> >(wchar_t const*, unsigned
long, std::__cxx11::basic_string<char, std::char_traits<char>,
std::allocator<char> >&, unsigned long, std::locale const&)':

Logger.cpp:(.text._ZN5boost3log11v2_mt_posix3aux12code_convertIwcSt11char_traitsIcESaIcEEENS_11enable_if_cIXaaaasrNS2_17is_character_typeIT_EE5valuesrNS8_IT0_EE5valuenestS9_stSB_EbE4typeEPKS9_mRNSt7__cxx1112basic_stringISB_T1_T2_EEmRKSt6locale[_ZN5boost3log11v2_mt_posix3aux12code_convertIwcSt11char_traitsIcESaIcEEENS_11enable_if_cIXaaaasrNS2_17is_character_typeIT_EE5valuesrNS8_IT0_EE5valuenestS9_stSB_EbE4typeEPKS9_mRNSt7__cxx1112basic_stringISB_T1_T2_EEmRKSt6locale]+0x37):
undefined reference to
`boost::log::v2_mt_posix::aux::code_convert_impl(wchar_t const*, unsigned
long, std::__cxx11::basic_string<char, std::char_traits<char>,
std::allocator<char> >&, unsigned long, std::locale const&)'

CMakeFiles/main.dir/src/Logger.cpp.o: In function `void
boost::log::v2_mt_posix::sinks::basic_formatting_sink_frontend<char>::feed_record<boost::recursive_mutex,
boost::log::v2_mt_posix::sinks::basic_text_ostream_backend<char>
>(boost::log::v2_mt_posix::record_view const&, boost::recursive_mutex&,
boost::log::v2_mt_posix::sinks::basic_text_ostream_backend<char>&)':

Logger.cpp:(.text._ZN5boost3log11v2_mt_posix5sinks30basic_formatting_sink_frontendIcE11feed_recordINS_15recursive_mutexENS2_26basic_text_ostream_backendIcEEEEvRKNS1_11record_viewERT_RT0_[_ZN5boost3log11v2_mt_posix5sinks30basic_formatting_sink_frontendIcE11feed_recordINS_15recursive_mutexENS2_26basic_text_ostream_backendIcEEEEvRKNS1_11record_viewERT_RT0_]+0x141):
undefined reference to
`boost::log::v2_mt_posix::sinks::basic_text_ostream_backend<char>::consume(boost::log::v2_mt_posix::record_view
const&, std::__cxx11::basic_string<char, std::char_traits<char>,
std::allocator<char> > const&)'

CMakeFiles/main.dir/src/Logger.cpp.o: In function `void
boost::log::v2_mt_posix::sinks::basic_formatting_sink_frontend<char>::feed_record<boost::recursive_mutex,
boost::log::v2_mt_posix::sinks::text_file_backend>(boost::log::v2_mt_posix::record_view
const&, boost::recursive_mutex&,
boost::log::v2_mt_posix::sinks::text_file_backend&)':

Logger.cpp:(.text._ZN5boost3log11v2_mt_posix5sinks30basic_formatting_sink_frontendIcE11feed_recordINS_15recursive_mutexENS2_17text_file_backendEEEvRKNS1_11record_viewERT_RT0_[_ZN5boost3log11v2_mt_posix5sinks30basic_formatting_sink_frontendIcE11feed_recordINS_15recursive_mutexENS2_17text_file_backendEEEvRKNS1_11record_viewERT_RT0_]+0x141):
undefined reference to
`boost::log::v2_mt_posix::sinks::text_file_backend::consume(boost::log::v2_mt_posix::record_view
const&, std::__cxx11::basic_string<char, std::char_traits<char>,
std::allocator<char> > const&)'

CMakeFiles/main.dir/src/Logger.cpp.o: In function `void
boost::log::v2_mt_posix::sinks::basic_formatting_sink_frontend<char>::feed_record<boost::log::v2_mt_posix::aux::fake_mutex,
boost::log::v2_mt_posix::sinks::basic_text_ostream_backend<char>
>(boost::log::v2_mt_posix::record_view const&,
boost::log::v2_mt_posix::aux::fake_mutex&,
boost::log::v2_mt_posix::sinks::basic_text_ostream_backend<char>&)':

Logger.cpp:(.text._ZN5boost3log11v2_mt_posix5sinks30basic_formatting_sink_frontendIcE11feed_recordINS1_3aux10fake_mutexENS2_26basic_text_ostream_backendIcEEEEvRKNS1_11record_viewERT_RT0_[_ZN5boost3log11v2_mt_posix5sinks30basic_formatting_sink_frontendIcE11feed_recordINS1_3aux10fake_mutexENS2_26basic_text_ostream_backendIcEEEEvRKNS1_11record_viewERT_RT0_]+0x141):
undefined reference to
`boost::log::v2_mt_posix::sinks::basic_text_ostream_backend<char>::consume(boost::log::v2_mt_posix::record_view
const&, std::__cxx11::basic_string<char, std::char_traits<char>,
std::allocator<char> > const&)'

CMakeFiles/main.dir/src/Logger.cpp.o: In function `void
boost::log::v2_mt_posix::sinks::basic_formatting_sink_frontend<char>::feed_record<boost::log::v2_mt_posix::aux::fake_mutex,
boost::log::v2_mt_posix::sinks::text_file_backend>(boost::log::v2_mt_posix::record_view
const&, boost::log::v2_mt_posix::aux::fake_mutex&,
boost::log::v2_mt_posix::sinks::text_file_backend&)':

Logger.cpp:(.text._ZN5boost3log11v2_mt_posix5sinks30basic_formatting_sink_frontendIcE11feed_recordINS1_3aux10fake_mutexENS2_17text_file_backendEEEvRKNS1_11record_viewERT_RT0_[_ZN5boost3log11v2_mt_posix5sinks30basic_formatting_sink_frontendIcE11feed_recordINS1_3aux10fake_mutexENS2_17text_file_backendEEEvRKNS1_11record_viewERT_RT0_]+0x141):
undefined reference to
`boost::log::v2_mt_posix::sinks::text_file_backend::consume(boost::log::v2_mt_posix::record_view
const&, std::__cxx11::basic_string<char, std::char_traits<char>,
std::allocator<char> > const&)'

collect2: error: ld returned 1 exit status

make[2]: *** [main] Error 1

make[1]: *** [CMakeFiles/main.dir/all] Error 2

Can someone please help? I have tried everything from trying to dynamically
and statically link. I've added both "log" and "log_setup" to the
find_packages in cmake and have also explicitly specified the locations of
those libraries as well.

Please let me know if there is anything else to try.

Thanks

--
Karmethia Thompson
Applied Mathematics, PhD

_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
Reply | Threaded
Open this post in threaded view
|

Re: Boost Log 1.65.1 Linking Issue

Boost - Dev mailing list
On 9/15/20 5:34 PM, Karmethia Thompson via Boost wrote:
> Good morning,
>
> I am trying to create a logger that uses Boost Log. I was successful
> getting my code to compile with 1.63.0, so I know that I am not too far off
> of the mark. cmake/make throws a linking issues whenever I attempt to
> create a sink:

[snip]

> Can someone please help? I have tried everything from trying to dynamically
> and statically link. I've added both "log" and "log_setup" to the
> find_packages in cmake and have also explicitly specified the locations of
> those libraries as well.

The error messages indicate you're missing symbols defined in libboost_log.

I think you either didn't specify the library to link with, or you might
be affected by this bug:

https://gitlab.kitware.com/cmake/cmake/-/issues/20638
https://github.com/boostorg/log/issues/46

The solution is to use target_link_libraries to explicitly link with
libboost_log, e.g.:

target_link_libraries(${MY_TARGET} boost_log)

_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
Reply | Threaded
Open this post in threaded view
|

Re: Boost Log 1.65.1 Linking Issue

Boost - Dev mailing list
Andrey thanks for your reply. I tried that as well without success. My
cmake file is below:

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
add_definitions(-DBOOST_LOG_DYN_LINK=1)

## Common parameters.
# Set common path variables. (YOURS MAY BE DIFFERENT)
set(BOOST_ROOT "$ENV{BOOST_ROOT}")

set(ARMADILLO_HOME "$ENV{ARMADILLO_ROOT}")
include_directories (${ARMADILLO_HOME}/include)
link_directories (${ARMADILLO_HOME}/lib64)
#SET(CMAKE_VERBOSE_MAKEFILE ON)

# Set the path to Boost
#SET(Boost_USE_STATIC_LIBS ON)
#SET(Boost_USE_MULTITHREADED ON)
find_package (Boost COMPONENTS log log_setup system thread filesystem
date_time  REQUIRED)
include_directories (${Boost_INCLUDE_DIRS})
link_directories (${Boost_LIBRARY_DIRS})
#link_libraries(${CMAKE_THREAD_LIBS_INIT} ${Boost_LIBRARIES})

    include_directories("${CMAKE_CURRENT_SOURCE_DIR}/include")
    include_directories("${CMAKE_CURRENT_SOURCE_DIR}/include/modules")

    # Retrieve the list of source files.
    file (GLOB SOURCE ${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp)
    file (GLOB MODULE_SOURCE ${CMAKE_CURRENT_SOURCE_DIR}/src/modules/*.cpp)

    add_executable (main
    main.cpp
    ${SOURCE}
    ${MODULE_SOURCE}
                   )
target_link_libraries(main boost_log)
target_link_libraries (main ${Boost_LIBRARIES} -lpthread)

On Tue, Sep 15, 2020 at 12:14 PM Andrey Semashev via Boost <
[hidden email]> wrote:

> On 9/15/20 5:34 PM, Karmethia Thompson via Boost wrote:
> > Good morning,
> >
> > I am trying to create a logger that uses Boost Log. I was successful
> > getting my code to compile with 1.63.0, so I know that I am not too far
> off
> > of the mark. cmake/make throws a linking issues whenever I attempt to
> > create a sink:
>
> [snip]
>
> > Can someone please help? I have tried everything from trying to
> dynamically
> > and statically link. I've added both "log" and "log_setup" to the
> > find_packages in cmake and have also explicitly specified the locations
> of
> > those libraries as well.
>
> The error messages indicate you're missing symbols defined in libboost_log.
>
> I think you either didn't specify the library to link with, or you might
> be affected by this bug:
>
> https://gitlab.kitware.com/cmake/cmake/-/issues/20638
> https://github.com/boostorg/log/issues/46
>
> The solution is to use target_link_libraries to explicitly link with
> libboost_log, e.g.:
>
> target_link_libraries(${MY_TARGET} boost_log)
>
> _______________________________________________
> Unsubscribe & other changes:
> http://lists.boost.org/mailman/listinfo.cgi/boost
>


--
Karmethia Thompson
Applied Mathematics, PhD

_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
Reply | Threaded
Open this post in threaded view
|

Re: Boost Log 1.65.1 Linking Issue

Boost - Dev mailing list
On 9/15/20 7:44 PM, Karmethia Thompson via Boost wrote:

> Andrey thanks for your reply. I tried that as well without success. My
> cmake file is below:
>
> set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
> add_definitions(-DBOOST_LOG_DYN_LINK=1)
>
> ## Common parameters.
> # Set common path variables. (YOURS MAY BE DIFFERENT)
> set(BOOST_ROOT "$ENV{BOOST_ROOT}")
>
> set(ARMADILLO_HOME "$ENV{ARMADILLO_ROOT}")
> include_directories (${ARMADILLO_HOME}/include)
> link_directories (${ARMADILLO_HOME}/lib64)
> #SET(CMAKE_VERBOSE_MAKEFILE ON)
>
> # Set the path to Boost
> #SET(Boost_USE_STATIC_LIBS ON)
> #SET(Boost_USE_MULTITHREADED ON)
> find_package (Boost COMPONENTS log log_setup system thread filesystem
> date_time  REQUIRED)
> include_directories (${Boost_INCLUDE_DIRS})
> link_directories (${Boost_LIBRARY_DIRS})
> #link_libraries(${CMAKE_THREAD_LIBS_INIT} ${Boost_LIBRARIES})
>
>      include_directories("${CMAKE_CURRENT_SOURCE_DIR}/include")
>      include_directories("${CMAKE_CURRENT_SOURCE_DIR}/include/modules")
>
>      # Retrieve the list of source files.
>      file (GLOB SOURCE ${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp)
>      file (GLOB MODULE_SOURCE ${CMAKE_CURRENT_SOURCE_DIR}/src/modules/*.cpp)
>
>      add_executable (main
>      main.cpp
>      ${SOURCE}
>      ${MODULE_SOURCE}
>                     )
> target_link_libraries(main boost_log)
> target_link_libraries (main ${Boost_LIBRARIES} -lpthread)

I'm not sure, but I think the above would generate incorrect order of
libraries in the linker command line. You need to ensure that boost_log
comes after boost_log_setup, and their dependencies come after still. So
it should be: boost_log_setup, boost_log, boost_thread,
boost_filesystem, boost_system, boost_date_time, pthread.

You can see the linker command line if you add VERBOSE=1 environment
variable before make.

Also, you don't need to specify -l in target_link_libraries (i.e. you
should specify pthread instead of -lpthread).

Also, please don't top-post.

_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
Reply | Threaded
Open this post in threaded view
|

Re: Boost Log 1.65.1 Linking Issue

Boost - Dev mailing list
On 9/15/20 8:02 PM, Andrey Semashev wrote:

> On 9/15/20 7:44 PM, Karmethia Thompson via Boost wrote:
>> Andrey thanks for your reply. I tried that as well without success. My
>> cmake file is below:
>>
>> set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
>> add_definitions(-DBOOST_LOG_DYN_LINK=1)
>>
>> ## Common parameters.
>> # Set common path variables. (YOURS MAY BE DIFFERENT)
>> set(BOOST_ROOT "$ENV{BOOST_ROOT}")
>>
>> set(ARMADILLO_HOME "$ENV{ARMADILLO_ROOT}")
>> include_directories (${ARMADILLO_HOME}/include)
>> link_directories (${ARMADILLO_HOME}/lib64)
>> #SET(CMAKE_VERBOSE_MAKEFILE ON)
>>
>> # Set the path to Boost
>> #SET(Boost_USE_STATIC_LIBS ON)
>> #SET(Boost_USE_MULTITHREADED ON)
>> find_package (Boost COMPONENTS log log_setup system thread filesystem
>> date_time  REQUIRED)
>> include_directories (${Boost_INCLUDE_DIRS})
>> link_directories (${Boost_LIBRARY_DIRS})
>> #link_libraries(${CMAKE_THREAD_LIBS_INIT} ${Boost_LIBRARIES})
>>
>>      include_directories("${CMAKE_CURRENT_SOURCE_DIR}/include")
>>      include_directories("${CMAKE_CURRENT_SOURCE_DIR}/include/modules")
>>
>>      # Retrieve the list of source files.
>>      file (GLOB SOURCE ${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp)
>>      file (GLOB MODULE_SOURCE
>> ${CMAKE_CURRENT_SOURCE_DIR}/src/modules/*.cpp)
>>
>>      add_executable (main
>>      main.cpp
>>      ${SOURCE}
>>      ${MODULE_SOURCE}
>>                     )
>> target_link_libraries(main boost_log)
>> target_link_libraries (main ${Boost_LIBRARIES} -lpthread)
>
> I'm not sure, but I think the above would generate incorrect order of
> libraries in the linker command line. You need to ensure that boost_log
> comes after boost_log_setup, and their dependencies come after still. So
> it should be: boost_log_setup, boost_log, boost_thread,
> boost_filesystem, boost_system, boost_date_time, pthread.
>
> You can see the linker command line if you add VERBOSE=1 environment
> variable before make.
>
> Also, you don't need to specify -l in target_link_libraries (i.e. you
> should specify pthread instead of -lpthread).
>
> Also, please don't top-post.

And I'm assuming you're linking with shared libraries of Boost. If not,
you need to *not* define BOOST_LOG_DYN_LINK.

_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
Reply | Threaded
Open this post in threaded view
|

Re: Boost Log 1.65.1 Linking Issue

Boost - Dev mailing list
In reply to this post by Boost - Dev mailing list
Andrey Semashev wrote:

> I'm not sure, but I think the above would generate incorrect order of
> libraries in the linker command line. You need to ensure that boost_log
> comes after boost_log_setup, and their dependencies come after still.

CMake automatically orders libraries so that the dependencies come after.
Unfortunately, FindBoost has a bug and declares log as depending on
log_setup, rather than vice versa.

https://github.com/Kitware/CMake/blob/bdcde7762c71cd27fcba6dc1a3efe12fa7a09fef/Modules/FindBoost.cmake#L1177

No matter how you order the libraries in target_link_libraries, the order
between these two will never be correct.

Not sure if this is the problem here though.


_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
Reply | Threaded
Open this post in threaded view
|

Re: Boost Log 1.65.1 Linking Issue

Boost - Dev mailing list
In reply to this post by Boost - Dev mailing list
Although, now that I think of it, the shown CMakeLists.txt file didn't use
imported targets, so perhaps the order of libraries is literal and putting
log_setup before log may indeed solve things.

-----Original Message-----
From: Peter Dimov
Sent: Tuesday, September 15, 2020 20:28
To: [hidden email]
Subject: Re: [boost] Boost Log 1.65.1 Linking Issue

Andrey Semashev wrote:

> I'm not sure, but I think the above would generate incorrect order of
> libraries in the linker command line. You need to ensure that boost_log
> comes after boost_log_setup, and their dependencies come after still.

CMake automatically orders libraries so that the dependencies come after.
Unfortunately, FindBoost has a bug and declares log as depending on
log_setup, rather than vice versa.

https://github.com/Kitware/CMake/blob/bdcde7762c71cd27fcba6dc1a3efe12fa7a09fef/Modules/FindBoost.cmake#L1177

No matter how you order the libraries in target_link_libraries, the order
between these two will never be correct.

Not sure if this is the problem here though.



_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
Reply | Threaded
Open this post in threaded view
|

Re: Boost Log 1.65.1 Linking Issue

Boost - Dev mailing list
In reply to this post by Boost - Dev mailing list

>> On 9/15/20 7:44 PM, Karmethia Thompson via Boost wrote:
>>> Andrey thanks for your reply. I tried that as well without success. My
>>> cmake file is below:
>>>
>>> set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
>>> add_definitions(-DBOOST_LOG_DYN_LINK=1)
>>>
>>> ## Common parameters.
>>> # Set common path variables. (YOURS MAY BE DIFFERENT)
>>> set(BOOST_ROOT "$ENV{BOOST_ROOT}")
>>>
>>> set(ARMADILLO_HOME "$ENV{ARMADILLO_ROOT}")
>>> include_directories (${ARMADILLO_HOME}/include)
>>> link_directories (${ARMADILLO_HOME}/lib64)
>>> #SET(CMAKE_VERBOSE_MAKEFILE ON)
>>>
>>> # Set the path to Boost
>>> #SET(Boost_USE_STATIC_LIBS ON)
>>> #SET(Boost_USE_MULTITHREADED ON)
>>> find_package (Boost COMPONENTS log log_setup system thread filesystem
>>> date_time  REQUIRED)
>>> include_directories (${Boost_INCLUDE_DIRS})
>>> link_directories (${Boost_LIBRARY_DIRS})
>>> #link_libraries(${CMAKE_THREAD_LIBS_INIT} ${Boost_LIBRARIES})
>>>
>>> include_directories("${CMAKE_CURRENT_SOURCE_DIR}/include")
>>> include_directories("${CMAKE_CURRENT_SOURCE_DIR}/include/modules")
>>>
>>>      # Retrieve the list of source files.
>>>      file (GLOB SOURCE ${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp)
>>>      file (GLOB MODULE_SOURCE
>>> ${CMAKE_CURRENT_SOURCE_DIR}/src/modules/*.cpp)
>>>
>>>      add_executable (main
>>>      main.cpp
>>>      ${SOURCE}
>>>      ${MODULE_SOURCE}
>>>                     )
>>> target_link_libraries(main boost_log)
>>> target_link_libraries (main ${Boost_LIBRARIES} -lpthread)
It likely doesn't really solve your problem, but don't use
include_directories, link_directories but the target_* variants of that.
Similar don't use Boost_INCLUDE_DIRS, Boost_LIBRARIES, ... but use the
targets provided. I.e. Boost::log

This will make your code much cleaner, shorter, hence easier to maintain
and maybe already solves your problem.

Maybe including Boost::log_setup before Boost::log in your
target_link_libraries solves the problem.

Please try that and if that fails run "make VERBOSE=1" and post the
relevant linker line.




_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost

smime.p7s (6K) Download Attachment