boost是大家知道的一个非常优秀的库,一般只需要include它的hpp即可使用,但有些库,需要编译才能使用(当然也可以以源码的方式嵌入到工程),我今天要讲的就是以源码嵌入到工程中。
在罗剑锋先生的所著的《Boost程序库完全开发指南 第二版》(以下简称指南)的第402页中提到,但我使用书中提到的方法无法编译、链接通过。后来反复修改,编译、链接通过,现记录下来,备忘,也希望能解决同仁类似的问题。
修改的步骤如下:
1、将libs/filesystem/src/path.cpp中的default_codcvt_buf_size注释掉。
2、将libs/filesystem/src/path.cpp中的dot,dot_path,dot_dot_path改名,比如mydot,etc. (与指南中不同)
3、在你自己的文件中加入如下代码:
#define BOOST_ALL_NO_LIB
#include <libs/system/src/error_code.cpp> //是本人新加的,指南中没有
#include <libs/filesystem/src/codecvt_error_category.cpp>
#include <libs/filesystem/src/operations.cpp>
#include <libs/filesystem/src/path_traits.cpp>
#include <libs/filesystem/src/path.cpp>
#include <libs/filesystem/src/portability.cpp>
#include <libs/filesystem/src/unique_path.cpp>
#include <libs/filesystem/src/utf8_codecvt_facet.cpp>
#include <libs/filesystem/src/windows_file_codecvt.cpp>
#include <boost/filesystem.hpp>
不同的地方,我已用红色标注,在此仍然感谢罗剑锋先生。
注,上述代码在boost 1.54,1.55中编译通过