简体   繁体   中英

c++ - Boost.Log error with namespaces

Trying to build the next program which use Boost::library and trying to create a new logger:

#include <string>
#include <boost/log/core.hpp>
#include <boost/log/trivial.hpp>
#include <boost/log/expressions.hpp>

class TestClass
{    
     ...        
     boost::log::sources::logger lg;
};

My Cmake file for building this file:

set(Boost_USE_STATIC_LIBS ON)
set(Boost_USE_MULTITHREADED ON)
set(Boost_USE_STATIC_RUNTIME OFF)

find_package(Boost 1.63.0
             COMPONENTS system
                        filesystem
                        log
                        log_setup
                        thread
                        unit_test_framework
             REQUIRED)

include_directories(SYSTEM ${Boost_INCLUDE_DIRS})

file(GLOB PROJECT_SOURCES sources/*.cpp
                          sources/configuration/*.cpp)
file(GLOB PROJECT_HEADERS sources/*.h
                          sources/configuration/*.h)

add_executable(${PROJECT_NAME}
               ${PROJECT_SOURCES}
               ${PROJECT_HEADERS})
target_link_libraries(${PROJECT_NAME}
                      ${Boost_LIBRARIES}
                      Boost::log)

But during linking I get the next error:

error: 'logger' in namespace 'boost::log::v2_mt_nt5::sources' does not name a type
         boost::log::sources::logger log;

Why my namespace boost::log::sources is converted to boost::log::v2_mt_nt5::sources ? How to solve this issue?

您只是缺少一个include指令:

#include <boost/log/sources/logger.hpp>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM