【发布时间】:2012-12-25 08:22:01
【问题描述】:
我正在尝试在 CodeBlocks 12.11 上构建和运行 Boost.Log 库。我没有boost和boost.log的经验,想学习,所以,首先我需要安装它。
安装提升
首先我按照how to install boost using codeblocks上的步骤进行操作
结果在两台不同的计算机上(都有 Windows 7)我在 %mypath%\boost\lib 中得到了不同的文件列表 (在一台计算机上只有 6 个文件,在另外 52 个)
更大的列表是:
- libboost_chrono-mgw47-mt-1_52.a
- libboost_chrono-mgw47-mt-d-1_52.a
- libboost_date_time-mgw47-mt-1_52.a
- libboost_date_time-mgw47-mt-d-1_52.a
- libboost_exception-mgw47-mt-1_52.a
- libboost_exception-mgw47-mt-d-1_52.a
- libboost_filesystem-mgw47-mt-1_52.a
- libboost_filesystem-mgw47-mt-d-1_52.a
- libboost_graph-mgw47-mt-1_52.a
- libboost_graph-mgw47-mt-d-1_52.a
- libboost_iostreams-mgw47-mt-1_52.a
- libboost_iostreams-mgw47-mt-d-1_52.a
- libboost_locale-mgw47-mt-1_52.a
- libboost_locale-mgw47-mt-d-1_52.a
- libboost_math_c99-mgw47-mt-1_52.a
- libboost_math_c99-mgw47-mt-d-1_52.a
- libboost_math_c99f-mgw47-mt-1_52.a
- libboost_math_c99f-mgw47-mt-d-1_52.a
- libboost_math_c99l-mgw47-mt-1_52.a
- libboost_math_c99l-mgw47-mt-d-1_52.a
- libboost_math_tr1-mgw47-mt-1_52.a
- libboost_math_tr1-mgw47-mt-d-1_52.a
- libboost_math_tr1f-mgw47-mt-1_52.a
- libboost_math_tr1f-mgw47-mt-d-1_52.a
- libboost_math_tr1l-mgw47-mt-1_52.a
- libboost_math_tr1l-mgw47-mt-d-1_52.a
- libboost_prg_exec_monitor-mgw47-mt-1_52.a
- libboost_prg_exec_monitor-mgw47-mt-d-1_52.a
- libboost_program_options-mgw47-mt-1_52.a
- libboost_program_options-mgw47-mt-d-1_52.a
- libboost_random-mgw47-mt-1_52.a
- libboost_random-mgw47-mt-d-1_52.a
- libboost_regex-mgw47-mt-1_52.a
- libboost_regex-mgw47-mt-d-1_52.a
- libboost_serialization-mgw47-mt-1_52.a
- libboost_serialization-mgw47-mt-d-1_52.a
- libboost_signals-mgw47-mt-1_52.a
- libboost_signals-mgw47-mt-d-1_52.a
- libboost_system-mgw47-mt-1_52.a
- libboost_system-mgw47-mt-d-1_52.a
- libboost_test_exec_monitor-mgw47-mt-1_52.a
- libboost_test_exec_monitor-mgw47-mt-d-1_52.a
- libboost_thread-mgw47-mt-1_52.a
- libboost_thread-mgw47-mt-d-1_52.a
- libboost_timer-mgw47-mt-1_52.a
- libboost_timer-mgw47-mt-d-1_52.a
- libboost_unit_test_framework-mgw47-mt-1_52.a
- libboost_unit_test_framework-mgw47-mt-d-1_52.a
- libboost_wave-mgw47-mt-1_52.a
- libboost_wave-mgw47-mt-d-1_52.a
- libboost_wserialization-mgw47-mt-1_52.a
- libboost_wserialization-mgw47-mt-d-1_52.a
它是通过 bjam 消息安装的:
...failed updating 10 targets...
...skipped 16 targets...
...updated 764 targets...
该列表是否已满,或者我安装的 boost 错过了一些库? 为什么两台不同的计算机会对相同的操作给出不同的结果(我两次从链接中遵循相同的步骤)? (只有 6 个结果库的比较没有 VC2010,有 52 个库的比较有 VC2010,这可能是原因吗?)
安装 boost.log
然后,在有 52 个库的机器上,我开始按照how to install boost.log 的步骤安装 boost.log
还有两个额外的库:
- libboost_log_setup-mgw47-mt-1_52.a(大小 22733 kb)
- libboost_log_setup-mgw47-mt-d-1_52.a(大小 74933 kb)
来自 bjam 的下一条结果消息:
...failed updating 6 targets...
...skipped 10 targets...
...updated 225 targets...
然后我从 boost.log 发行版中取样:
#include <iostream>
//#define BOOST_LOG_DYN_LINK
#include <boost/shared_ptr.hpp>
#include <boost/make_shared.hpp>
#include <boost/log/common.hpp>
#include <boost/log/formatters.hpp>
#include <boost/log/filters.hpp>
#include <boost/log/utility/init/to_file.hpp>
#include <boost/log/utility/init/to_console.hpp>
#include <boost/log/utility/init/common_attributes.hpp>
#include <boost/log/attributes/timer.hpp>
namespace logging = boost::log;
namespace fmt = boost::log::formatters;
namespace flt = boost::log::filters;
namespace sinks = boost::log::sinks;
namespace attrs = boost::log::attributes;
namespace src = boost::log::sources;
namespace keywords = boost::log::keywords;
using boost::shared_ptr;
int main(int argc, char* argv[])
{
logging::init_log_to_console(std::clog, keywords::format = "%TimeStamp%: %_%");
logging::add_common_attributes();
src::logger lg;
BOOST_LOG(lg) << "Hello, World!";
return 0;
}
将库添加到项目(以及包含文件的路径): 还有 libboost_log_setup-mgw47-mt-d-1_52.a
但在编译时出现错误:
obj\Debug\main.o||In function 'ZN5boost10log_mt_nt57sources12basic_loggerIcNS1_6loggerENS1_19single_thread_modelEED2Ev':|
C:\Program Files (x86)\CodeBlocks\include\boost-1_52\boost\log\sources\basic_logger.hpp|88|undefined reference to `boost::log_mt_nt5::basic_attribute_set<char>::~basic_attribute_set()'|
又不知道怎么解决。
请解释一下(如果可能的话):
- 我怎么知道我的 boost 编译/安装已满,如果没有,该怎么办(我确定给我 6 个库的安装没有满,但我不知道该怎么办)?
- 我如何知道我的 boost.log 编译已满?
- 我读到我必须将 boost.lib 构建为共享对象,但 libs 位于子目录“link-static”中,尽管命令 runtime-link=shared 用于 bjam。我应该对此做些什么吗?
- 我遇到的错误应该怎么办?
感谢您的帮助。
【问题讨论】:
-
我尝试了使用 boost 线程的示例,并得到了相同的“未定义引用”问题。所以我决定我的提升构建是错误的。从nuwen.net/mingw.html 我下载了gcc 4.7.2 并且已经安装了boost(它有26 个库,所以我的52 个编译(一个版本,一个调试)是正确的)。我在现有的 insode CodeBlocks 上复制了新的 MinGW 目录。并再次尝试了提升线程示例。又得到了那个“未定义的引用”错误! =( 为什么是现在?我发现如果没有链接到 C 运行时库,可能会发生这种情况。可能是问题吗?
标签: windows boost installation codeblocks boost-log