c ++ - 名称空间的Boost.Log错误

时间:2017-05-01 20:39:57

标签: c++ boost cmake boost-log

尝试构建下一个使用Boost :: library并尝试创建新记录器的程序:

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

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

用于构建此文件的我的Cmake文件:

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)

但是在链接过程中我得到了下一个错误:

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

为什么我的名称空间boost::log::sources已转换为boost::log::v2_mt_nt5::sources?如何解决这个问题?

1 个答案:

答案 0 :(得分:1)

您只是缺少一个include指令:

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