boost makeboost shared library在哪个动态库

Boost 库安装、编译问题笔记_Linux编程_Linux公社-Linux系统门户网站
你好,游客
Boost 库安装、编译问题笔记
来源:Linux社区&
作者:Linux
环境: Linux s.9-67.ELsmp #1 SMP Wed Nov 7 13:58:04 EST
i686 i386 GNU/Linux&& & & & gcc version 3.2.3
( Linux 3.2.3-47.3)&& & & & boost 1.37.0
去年10月份用过一次再没用过了。今天要用 regex 库,生疏了。小记一下。以备以后参考。&boost 库做得真好。在Windows 平台,Linux 平台下编译都很顺利。hp aCC 也宣称对 boost 1.35 完全支持 。
全部编译是很痛苦的过程。如果要使用哪个库,只需要在 $(boost_root)/libs/下找到感兴趣的库,在 build 目录中,选择编译器使用的 makefile,编译即可。
例如,我这里使用 boost 1.37 的 regex 库。解压 boost 后根目录是 c:\boost_1_37_0。&然后到下面的目录
c:\boost_1_37_0\libs\regex\build&&看到一大堆的 .mak 文件。根据名字就可以看出来自己需要哪个 .mak 文件。这里我用gcc编译器,所以选择 gcc.mak 。
编译器可以根据 makefile 文件或参数生成 8 个库。即静态\动态、release\debug 、多线程\单线程 库。从名字上看, debug 版本比其它版本的多一个 &_d&, 多线程比其它版本的多一个"_mt"。regex 库在 linux 平台下生成的库文件名列表如下:&//动态库的两个版本
libboost_regex-gcc-1_37.so& libboost_regex-gcc-d-1_37.so&//静态库的两个版本
ibboost_regex-gcc-1_37.a&
libboost_regex-gcc-d-1_37.a&// 多线程动态的两个版本&libboost_regex-gcc-mt -1_37.SO&
libboost_regex-gcc-mt-d-1_37.so
//多线程静态的两个版本&libboost_regex-gcc-mt -1_37.a&
libboost_regex-gcc-mt-d-1_37.a
一小会儿就编译好了。编译后生成的库文件在。&使用时,需要在 makefile 中用 -I 选项添加 boost 根目录的路径。如果使用动态连接库,还需要在 -L选项中添加对 .so 文件的引用。详细的解释援引下面的论述。&&
使用boost::regex的问题&单独编译了regex,生成了libboost_regex-gcc-1_34.a,现在试验regex能否生效,代码如下:&#include&boost/regex.hpp&&int main(int argc,char * argv[])&{& & & &
boost::regex e("test");& & & &
return 0;&}&#g++ regex.cpp -I /path/to/boostroot -L/path/to/libboost_regex-gcc-1_34.a -o regex&报错:&/tmp/ccf4WLI8.o(.gnu.linkonce.t._ZN5boost11basic_regexIcNS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEE6assignEPKcS7_j+0x13): In function `boost::basic_regex&char, boost::regex_traits&char, boost::cpp_regex_traits&char& & &::assign(char const*, char const*, unsigned int)':&: undefined reference to `boost::basic_regex&char, boost::regex_traits&char, boost::cpp_regex_traits&char& & &::do_assign(char const*, char const*, unsigned int)'&collect2: ld returned 1 exit status&头文件可以找到,但库的连接好像有问题,然而库的路径应该是对的,请问这是怎么回事?
boost文档不是说的很清楚了吗?(boost_1_34_1/more/getting_started/unix-variants.html 第6节)
A.&You can specify the full path to each library:&$ c++ -I path/to/boost_1_34_1 example.cpp -o example "& & ~/boost/lib/libboost_regex-gcc34-mt-d-1_34.a&
B.&You can separately specify a directory to search (with -Ldirectory) and a library name to search for (with -llibrary,2 dropping the filename's leading lib and trailing suffix (.a in this case):&$ c++ -I path/to/boost_1_34_1 example.cpp -o example "& & -L~/boost/lib/ -lboost_regex-gcc34-mt-d-1_34
我使用的是 .so 。所以我的 makefile是:
CXXFLAGS& & & & =& -lgcc_s $(LIB) -lboost_regex-gcc-d-1_37&COMPILE.C& & & & = $(CC) -c $(INCLUDE) &MAKEEXE& & & & & & = $(CC) $(CXXFLAGS)&#可执行文件所依赖的.o 如果希望.o生成在依赖文件所在目录下,可以使用路径,如../pub/b.o &OBJ& & & & & & = regex_match_example.o&EXE& & & & & & = winner&all:& & & & & & $(EXE)&$(EXE):& & & & & & ${OBJ}&#'$^', 叫作&自动变量&(Automatic Variables),会使用VPATH提供的信息来查找对应的文件& & & & & &
$(MAKEEXE) $^ -o $@&%.o:& & & & & & %.cpp& & & & & &
$(COMPILE.C) $^ -o $@&clean:& & & & & & & & & &
rm -f *.o $(EXE) core
我编译成功后,将动态连接库复制到当前目录下,运行时提示找不到动态连接库&&提示找不到动态连接库./winner: error while loading shared libraries: libboost_regex-gcc-d-1_37.so: cannot open shared object file: No such file or directory&看一下程序的引用和连接库的版本信息,确实没问题:&用 ldd 查看文件的动态连接库信息,用 file 查看动态连接库版本信息[fancp@s12084 test]$ ldd winner& & & &
/lib/libcwait.so (0x00de9000)& & & &
libgcc_s.so.1 =& /lib/libgcc_s.so.1 (0x00db1000)& & & &
libboost_regex-gcc-d-1_37.so =& not found& & & &
libstdc++.so.5 =& /usr/lib/libstdc++.so.5 (0x)& & & &
libm.so.6 =& /lib/tls/libm.so.6 (0x00b51000)& & & &
libc.so.6 =& /lib/tls/libc.so.6 (0x00a23000)& & & &
/lib/ld-linux.so.2 (0x00a04000)&[fancp@s12084 test]$ file libboost_regex-gcc-d-1_37.so&libboost_regex-gcc-d-1_37.so: ELF 32-bit LSB shared object, Intel 80386, version 1 (SYSV), not stripped&[fancp@s12084 test]$&查看了一下,原来是环境变量中 LIB 中没有添加当前目录为搜索路径。
修改 .bash_profile 文件,在 LIB 后面加一个冒号加一个点,保存,退出 shell ,再重新进入。OK!
Boost 的详细介绍:Boost 的下载地址:
Boost程序库完全开发指南&&深入C++&准&标准库高清PDF版
下编译安装boost库
Ubuntu下编译boost 1.52b
Ubuntu编译安装boost并在eclipse C/C++中使用
本文永久更新链接地址:
相关资讯 & & &
& (08/08/:12)
& (08/08/:39)
& (08/08/:35)
   同意评论声明
   发表
尊重网上道德,遵守中华人民共和国的各项有关法律法规
承担一切因您的行为而直接或间接导致的民事或刑事法律责任
本站管理人员有权保留或删除其管辖留言中的任意内容
本站有权在网站内转载或引用您的评论
参与本评论即表明您已经阅读并接受上述条款make_shared and allocate_shared - 1.59.0
make_shared and allocate_shared
function templates
Consistent use of
can eliminate the need to use an explicit delete,
but alone it provides no support in avoiding explicit new.
There have been repeated requests from users for a factory function that creates
an object of a given type and returns a shared_ptr to it.
Besides convenience and style, such a function is also exception safe and
considerably faster because it can use a single allocation for both the object
and its corresponding control block, eliminating a significant portion of
shared_ptr's construction overhead.
This eliminates one of the major efficiency complaints about shared_ptr.
The header file &boost/make_shared.hpp& provides a family of overloaded function templates,
make_shared and allocate_shared, to address this need.
make_shared uses the global operator new to allocate memory,
whereas allocate_shared uses an user-supplied allocator, allowing finer control.
The rationale for choosing the name make_shared is that the expression
make_shared&Widget&() can be read aloud and conveys the intended meaning.
namespace boost {
template&typename T& class shared_
template&typename T&
shared_ptr&T& ();
template&typename T, typename A&
shared_ptr&T& ( A const & );
#if !defined( BOOST_NO_CXX11_VARIADIC_TEMPLATES ) && !defined( BOOST_NO_CXX11_RVALUE_REFERENCES )
// C++0x prototypes
template&typename T, typename... Args&
shared_ptr&T& ( Args && ... args );
template&typename T, typename A, typename... Args&
shared_ptr&T& ( A const & a, Args && ... args );
#else // no C++0X support
template&typename T, typename Arg1 &
shared_ptr&T& ( Arg1 const & arg1 );
template&typename T, typename Arg1, typename Arg2 &
shared_ptr&T& ( Arg1 const & arg1, Arg2 const & arg2 );
template&typename T, typename Arg1, typename Arg2, ..., typename ArgN &
shared_ptr&T& ( Arg1 const & arg1, Arg2 const & arg2, ..., ArgN const & argN );
template&typename T, typename A, typename Arg1 &
shared_ptr&T& ( A const & a, Arg1 const & arg1 );
template&typename T, typename A, typename Arg1, typename Arg2 &
shared_ptr&T& ( Arg1 const & arg1, Arg2 const & arg2 );
template&typename T, typename A, typename Arg1, typename Arg2, ..., typename ArgN &
shared_ptr&T& ( A const & a, Arg1 const & arg1, Arg2 const & arg2, ..., ArgN const & argN );
template&class T, class... Args&
shared_ptr&T& make_shared( Args && ... args );
template&class T, class A, class... Args&
shared_ptr&T& allocate_shared( A const & a, Args && ... args );
Requires: The expression new( pv ) T( std::forward&Args&(args)... ),
where pv is a void* pointing to storage suitable
to hold an object of type T,
shall be well-formed.
A shall be an Allocator,
as described in section 20.1.5 (Allocator requirements) of the C++ Standard.
The copy constructor and destructor of A shall not throw.
Effects: Allocates memory suitable for an object of type T
and constructs an object in it via the placement new expression new( pv ) T()
or new( pv ) T( std::forward&Args&(args)... ).
allocate_shared uses a copy of a to allocate memory.
If an exception is thrown, has no effect.
Returns: A shared_ptr instance that stores and owns the address
of the newly constructed object of type T.
Postconditions: get() != 0 && use_count() == 1.
Throws: bad_alloc, or an exception thrown from A::allocate
or the constructor of T.
Notes: This implementation allocates the memory required for the
returned shared_ptr and an object of type T in a single
allocation. This provides efficiency equivalent to an intrusive smart pointer.
The prototypes shown above are used if your compiler supports rvalue references
and variadic templates.
They perfectly forward the args parameters to
the constructors of T.
Otherwise, the implementation will fall back on
forwarding the arguments to the constructors of T as const references.
If you need to pass a non-const reference to a constructor of T,
you may do so by wrapping the parameter in a call to boost::ref.
In addition, you will be
limited to a maximum of 9 arguments (not counting the allocator argument of
allocate_shared).
boost::shared_ptr&std::string& x = boost::make_shared&std::string&("hello, world!");
std::cout << *x;
Copyright 2008 Peter Dimov. Copyright 2008 Frank Mori Hess.
Distributed under the Boost Software License,
Version 1.0. See accompanying file
or copy at .boost log库 使用十 - 博客频道 - CSDN.NET
Dean Chen的专栏
分类:c++ boost log
在的demo中,还有一些地方可以提高。首先,把所有和boost log相关的语句都移到logger.h文件中。任何使用boost log库的程序都可以include 这个logger.h文件。如果你想要不同的sink,可以修改一下InitLog函数。#include &boost/shared_ptr.hpp&
#include &boost/make_shared.hpp&
#include &boost/thread/thread.hpp&
#include &boost/log/core.hpp&
#include &boost/log/sinks/sync_frontend.hpp&
#include &boost/log/sinks/text_ostream_backend.hpp&
#include &boost/log/sources/record_ostream.hpp&
#include &boost/log/support/date_time.hpp&
#include &boost/log/common.hpp&
#include &boost/log/expressions.hpp&
#include &boost/log/attributes.hpp&
#include &boost/log/sinks.hpp&
#include &boost/log/sources/logger.hpp&
#include &boost/log/utility/setup/common_attributes.hpp&
#include &boost/log/utility/setup/common_attributes.hpp&
#include &boost/log/utility/setup/formatter_parser.hpp&
#include &boost/log/sources/severity_logger.hpp&
#include &boost/log/sources/severity_feature.hpp&
#include &fstream&
namespace logging = boost::
namespace attrs = boost::log::
namespace src = boost::log::
namespace sinks = boost::log::
namespace expr = boost::log::
namespace keywords = boost::log::
enum sign_severity_level {
void InitLog() {
typedef sinks::synchronous_sink&sinks::text_ostream_backend& TextS
// init sink1
boost::shared_ptr&sinks::text_ostream_backend& backend1 = boost::make_shared&sinks::text_ostream_backend&();
backend1-&add_stream(boost::shared_ptr&std::ostream&(new std::ofstream(&sign.log&)));
boost::shared_ptr&TextSink& sink1(new TextSink(backend1));
sink1-&set_formatter (
expr::format(&[%1%]&%2%&(%3%): %4%&)
% expr::format_date_time& boost::posix_time::ptime &(&TimeStamp&, &%Y-%m-%d %H:%M:%S&)
% expr::attr&sign_severity_level&(&Severity&)
% expr::attr&attrs::current_thread_id::value_type &(&ThreadID&)
% expr::smessage
sink1-&set_filter(expr::attr&sign_severity_level&(&Severity&) &= warning);
logging::core::get()-&add_sink(sink1);
// init sink2
boost::shared_ptr&sinks::text_ostream_backend& backend2 = boost::make_shared&sinks::text_ostream_backend&();
backend2-&auto_flush(true);
backend2-&add_stream(boost::shared_ptr&std::ostream&(new std::ofstream(&sign.csv&)));
boost::shared_ptr&TextSink& sink2(new TextSink(backend2));
sink2-&set_formatter (
expr::format(&%1%,%2%,%3%&)
% expr::format_date_time& boost::posix_time::ptime &(&TimeStamp&, &%Y-%m-%d %H:%M:%S&)
% expr::attr&sign_severity_level&(&Severity&)
% expr::smessage
sink2-&set_filter(expr::attr&sign_severity_level&(&Severity&) == report);
logging::core::get()-&add_sink(sink2);
logging::add_common_attributes();
logging::core::get()-&add_global_attribute(&ThreadID&, attrs::current_thread_id());
BOOST_LOG_INLINE_GLOBAL_LOGGER_DEFAULT(my_logger, src::severity_logger_mt&sign_severity_level&)其次, 阻止程序的crash. 看一下官方的文章:我采用了第二种解决方案,在main函数的退出语句之前加一行#include &logger.h&
int main(int, char*[]) {
InitLog();
src::severity_logger_mt&sign_severity_level&& lg = my_logger::get();
BOOST_LOG_SEV(lg, trace) && &A trace severity message&;
BOOST_LOG_SEV(lg, debug) && &A debug severity message&;
BOOST_LOG_SEV(lg, info) && &An informational severity message&;
BOOST_LOG_SEV(lg, warning) && &A warning severity message&;
BOOST_LOG_SEV(lg, error) && &An error severity message&;
BOOST_LOG_SEV(lg, fatal) && &A fatal severity message&;
BOOST_LOG_SEV(lg, report) && &A report severity message&;
logging::core::get()-&remove_all_sinks();
}下一次,将在两个sinks上采用rotation log.
sheismylife
排名:第36名
(17)(1)(5)(4)(9)(34)(2)(35)(6)(9)(15)(13)(1)(7)(96)(9)(30)(17)(17)(19)(21)(7)(12)(5)(0)(7)(17)(10)(1)(41)(4)(4)(63)(0)(8)(3)(24)(2)(2)(8)(9)(5)(17)(12)(64)(35)(51)(7)(2)(6)(7)(19)(1)(11)(6)(8)(3)(17)(4)(15)(4)(10)(13)(2)(23)(22)(18)(5)(24)(1)(3)(73)(1)(6)(5)(6)(3)(3)(1)(8)(3)(2)(2)(16)(4)(3)(1)(1)(1)(1)(8)(1)(3)(24)(26)(1)(6)(4)(4)(9)(5)(3)(4)(9)(6)(13)(2)(7)(2)(26)(13)(5)(1)(2)(1)(2)(6)
算法专家朋友的博客
清如许的博客2003年9月 C/C++大版内专家分月排行榜第二2002年6月 C/C++大版内专家分月排行榜第二2002年4月 C/C++大版内专家分月排行榜第二
2007年3月 C/C++大版内专家分月排行榜第三2007年2月 C/C++大版内专家分月排行榜第三2007年1月 C/C++大版内专家分月排行榜第三2003年7月 C/C++大版内专家分月排行榜第三
2003年9月 C/C++大版内专家分月排行榜第二2002年6月 C/C++大版内专家分月排行榜第二2002年4月 C/C++大版内专家分月排行榜第二
2007年3月 C/C++大版内专家分月排行榜第三2007年2月 C/C++大版内专家分月排行榜第三2007年1月 C/C++大版内专家分月排行榜第三2003年7月 C/C++大版内专家分月排行榜第三
本帖子已过去太久远了,不再提供回复功能。1833人阅读
ASM或C或C++(202)
[1]在windows下调用“bjam”缺省生成静态库,
命令行下得使用“bjam link=shared”生成动态库!
[2]boost 1.55在编译器中加入“_DLL”,“BOOST_DYN_LINK”两个宏定义,这样就会开启,对boost的动态链接库调用。
[3]boost 1.56使用&BOOST_ALL_DYN_LINK 宏定义,具体参考
-----------------------------------------
参考下面的方式可以编译出不同Visual Studio版本的库
bjam --toolset=msvc-12.0 即VS2013
bjam --toolset=msvc-10.0 即VS2010
bjam --toolset=msvc-9.0& 即VS2008
-----------------------------------------&#65279;&#65279;
编译64位库
bjam --build-type=complete toolset=msvc-12.0 address-model=64 --stagedir=&./stage_x64&
参考知识库
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:775419次
积分:10753
积分:10753
排名:第1183名
原创:306篇
转载:35篇
评论:167条
(2)(1)(5)(3)(1)(11)(5)(1)(2)(1)(2)(9)(3)(5)(3)(3)(8)(6)(3)(5)(8)(5)(12)(6)(3)(5)(13)(11)(12)(8)(10)(6)(4)(3)(2)(3)(1)(3)(3)(3)(2)(1)(1)(2)(2)(1)(3)(3)(4)(1)(1)(1)(5)(2)(2)(5)(5)(6)(3)(3)(4)(1)(2)(2)(5)(2)(1)(2)(2)(2)(1)(2)(3)(2)(7)(2)(3)(1)(1)(3)(2)(1)(8)(1)(3)(3)(3)(1)(1)(3)(1)(3)(1)(6)(4)(2)}

我要回帖

更多关于 boost shared library 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信