头文件可以找到,但库的连接好像有问题,然而库的路径应该是对的,请问这是怎么回事?
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
看一下程序的引用和连接库的版本信息,确实没问题:
用 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 (0x00340000)
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!