我尝试使用boost log,我创建了一个简单的类 logger.hpp
#ifndef LOGGER_H
#define LOGGER_H
//#define BOOST_ALL_DYN_LINK
#include <string>
#include <boost/log/core.hpp>
#include <boost/log/trivial.hpp>
#include <boost/log/expressions.hpp>
#include <boost/log/sinks/text_file_backend.hpp>
#include <boost/log/utility/setup/file.hpp>
#include <boost/log/utility/setup/common_attributes.hpp>
#include <boost/log/sources/severity_logger.hpp>
#include <boost/log/sources/record_ostream.hpp>
#include <boost/log/support/date_time.hpp>
#define MAX_FILE_SIZE 25*1024*1024
namespace logging = boost::log;
namespace attrs = boost::log::attributes;
namespace src = boost::log::sources;
namespace sinks = boost::log::sinks;
namespace expr = boost::log::expressions;
namespace keywords = boost::log::keywords;
class Logger {
protected:
void init();
public:
Logger();
static void trace(std::string);
static void debug(std::string);
static void info(std::string);
static void warning(std::string);
static void error(std::string);
static void fatal(std::string);
};
#endif
和logger.cpp
#include "header/logger.hpp"
Logger::Logger() {
this->init();
logging::add_common_attributes();
}
void Logger::init () {
logging::add_file_log
(
keywords::file_name = "sgoauth_%N.log",
keywords::rotation_size = MAX_FILE_SIZE
);
logging::core::get()->set_filter
(
logging::trivial::severity >= logging::trivial::info
);
}
void Logger::trace(std::string tra) {
BOOST_LOG_TRIVIAL(trace) << tra;
}
void Logger::debug(std::string deb) {
BOOST_LOG_TRIVIAL(debug) << deb;
}
void Logger::info(std::string inf) {
BOOST_LOG_TRIVIAL(info) << inf;
}
void Logger::warning(std::string war) {
BOOST_LOG_TRIVIAL(warning) << war;
}
void Logger::error(std::string err) {
BOOST_LOG_TRIVIAL(error) << err;
}
void Logger::fatal(std::string fat) {
BOOST_LOG_TRIVIAL(fatal) << fat;
}
当我创建一个简单的主要和我编译我没有任何错误,但当我添加只是在我的项目中包含我在pastbin链接中的错误显示
我的cmake文件
cmake_minimum_required(VERSION 2.8)
#Déclaration du projet
project(sgoauth)
#Define PATH
#Boost
set(BOOST_INCLUDEDIR /home/msouadji/lib/boost/include/)
set(BOOST_ROOT /home/msouadji/lib/boost/)
#Build Netlib
set ( CPP-NETLIB /home/msouadji/lib/cpp-netlib-fix-build )
#Placez vos exécutables dans des dossiers portant le nom du type de compilation
#(Release, Debug...).
set(EXECUTABLE_OUTPUT_PATH ./${CMAKE_BUILD_TYPE}/)
#include BOOST
set(Boost_USE_MULTITHREADED ON)
ADD_DEFINITIONS(-DBOOST_LOG_DYN_LINK)
set(Boost_COMPONENTS log thread date_time regex filesystem system log_setup REQUIRED)
find_package( Boost 1.53 REQUIRED ${Boost_COMPONENTS} )
find_package( OpenSSL )
include_directories(${Boost_INCLUDE_DIR})
#include CPP-NETLIB
set ( CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH} ${CPP-NETLIB} )
find_package ( cppnetlib 0.11.0 REQUIRED )
include_directories ( ${CPPNETLIB_INCLUDE_DIRS} )
#C++11
set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11" )
find_package( OpenSSL )
if (OPENSSL_FOUND)
add_definitions(-DBOOST_NETWORK_ENABLE_HTTPS)
include_directories(${OPENSSL_INCLUDE_DIR})
endif()
SET(source_files src/authloadconf.cpp src/authserver.cpp src/serverhandler.cpp
src/authhandler.cpp src/app.cpp src/httpclient.cpp src/httpsclient.cpp
src/request.cpp src/nfcapphandler.cpp src/unixclient.cpp
src/header/authexception.hpp src/logger.cpp)
#sgoauth
add_executable(sgoauth ${source_files} src/sgoauth_main.cpp)
target_link_libraries ( sgoauth
${Boost_LIBRARIES}
${CMAKE_THREAD_LIBS_INIT}
${CPPNETLIB_LIBRARIES}
pthread
)
# quicktest
set(VAR httpclienttest loggertest)
# loop over a, b,c with the variable f
foreach(exec ${VAR})
add_executable(${exec} ${source_files} src/quicktest/${exec}_main.cpp)
TARGET_LINK_LIBRARIES ( ${exec}
${Boost_LIBRARIES}
${CMAKE_THREAD_LIBS_INIT}
${CPPNETLIB_LIBRARIES}
pthread
)
endforeach(exec)
我不知道我的项目在哪里使用asio和cpp-netlib库可以帮助我吗?
答案 0 :(得分:2)
看起来你正在使用Boost Spirit V2和Boost Phoenix V3(后者可能由Boost Log间接使用)。
避免冲突和以获得改进的Phoenix实现定义
#define BOOST_SPIRIT_USE_PHOENIX_V3
之前包括任何提升标头,或使用-DBOOST_SPIRIT_USE_PHOENIX_V3
进行编译