没有合适的资源?快使用搜索试试~ 我知道了~
首页Linux boost库安装、编译问题小记
环境: Linux s12084 2.6.9-67.ELsmp #1 SMP Wed Nov 7 13:58:04 EST 2007 i686 i686 i386 GNU/Linux gcc version 3.2.3 20030502 (Red Hat Linux 3.2.3-47.3) boost 1.37.0 去年10月份用过一次再没用过了。要用 regex 库,生疏了。小记一下。以备以后参考。 boost 库做得真好。在windows 平台, linux 平台下编译都很顺利。hp aCC 也宣称对 boost 1.35 完全支持 。 全部编译是很痛苦的过程
资源详情
资源评论
资源推荐

Linux boost库安装、编译问题小记库安装、编译问题小记
环境: Linux s12084 2.6.9-67.ELsmp #1 SMP Wed Nov 7 13:58:04 EST 2007 i686 i686 i386 GNU/Linux
gcc version 3.2.3 20030502 (Red Hat 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:oost_1_37_0。
然后到下面的目录
c:oost_1_37_0libsegexuild
看到一大堆的 .mak 文件。根据名字可以看出来自己需要哪个 .mak 文件。这里我用gcc编译器,所以选择 gcc.mak 。
编译器可以根据 makefile 文件或参数生成 8 个库。即静态动态、releasedebug 、多线程单线程 库。从名字上看, 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的问题
来自:http://bbs.chinaunix.net/viewthread.php?tid=987718
单独编译了regex,生成了libboost_regex-gcc-1_34.a,现在试验regex能否生效,代码如下:
CODE:
#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节)
QUOTE:
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
QUOTE:
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
看一下程序的引用和连接库的版本信息,确实没问题:
















安全验证
文档复制为VIP权益,开通VIP直接复制

评论0