无法通过 boost::logger 进行编译
Posted
技术标签:
【中文标题】无法通过 boost::logger 进行编译【英文标题】:Troubles getting boost::logger to compile 【发布时间】:2018-09-06 13:02:24 【问题描述】:我正在努力让一些 boost::logging
演示应用程序运行。我有以下内容:
logger.cpp
:
#include <iostream>
#include <boost/fusion/iterator/equal_to.hpp>
#include <boost/log/core.hpp>
#include <boost/log/trivial.hpp>
#include <boost/log/expressions.hpp>
#include <boost/log/utility/setup/file.hpp>
namespace logging = boost::log;
namespace src = boost::log::sources;
namespace sinks = boost::log::sinks;
namespace keywords = boost::log::keywords;
namespace expr = boost::log::expressions;
void init()
logging::add_file_log("sample.log");
logging::core::get()->set_filter
(
logging::trivial::severity >= logging::trivial::info
);
int main(void)
init();
std::cout <<"Hello World!";
CMakeLists.txt
:
cmake_minimum_required(VERSION 2.6)
project(LOGGER)
set(BOOST_INCLUDEDIR "/path/to/env/include")
set(BOOST_ROOT "/path/to/env/include")
find_package(Boost REQUIRED)
message(STATUS Boost_LIBRARIES:)
message (STATUS $Boost_LIBRARIES)
message(STATUS BOOST_INCLUDEDIR:)
message(STATUS $BOOST_INCLUDEDIR)
ADD_EXECUTABLE(logger logger.cpp)
target_include_directories(logger PUBLIC $BOOST_INCLUDEDIR)
target_link_libraries(logger Boost::boost $Boost_LIBRARIES)
set (CMAKE_CXX_FLAGS "-g -Wall")
在make
我明白了:
$ make
Scanning dependencies of target logger
[ 50%] Building CXX object CMakeFiles/logger.dir/logger.cpp.o
[100%] Linking CXX executable logger
/usr/bin/ld: cannot find -lBoost::boost
collect2: error: ld returned 1 exit status
CMakeFiles/logger.dir/build.make:94: recipe for target 'logger' failed
make[2]: *** [logger] Error 1
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/logger.dir/all' failed
make[1]: *** [CMakeFiles/logger.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2
我不明白为什么! 我错过了什么或做错了什么?
【问题讨论】:
根据theadd_file_log
reference,您需要包含<boost/log/utility/setup/file.hpp>
。也许试试?
@Someprogrammerdude 箍,听起来不错,谢谢!我已经更新了问题 - 我现在遇到了一个找不到库的问题......嗯
【参考方案1】:
第一个问题是因为您没有包含正确的头文件。对于add_file_log
,需要<boost/log/utility/setup/file.hpp>
头文件。
对于第二个问题(应该是第二个问题,没有人喜欢移动的目标),如果你阅读the FindBoost
reference你会看到
Boost::boost Target for header-only dependencies (Boost include directory)
这不是您需要链接的库。从target_link_libraries
命令中删除它。
【讨论】:
以上是关于无法通过 boost::logger 进行编译的主要内容,如果未能解决你的问题,请参考以下文章
Truffle 部署的合约无法通过 Etherscan 进行验证
编译器无法在 SwiftUI 中的合理时间内对该表达式进行类型检查?