boost 和 cpp-netlib 使编译错误

发布于 2024-11-05 20:46:08 字数 2923 浏览 1 评论 0原文

[已解决] 创建了从 /usr/lib/lib/* 到 /usr/lib* 的符号链接

[更新 3] 新版本:

好吧,我想我修复了一些

使用 find / -name " libboost_system.*" outout 是

/usr/include/boost/lib/libboost_system.so
/usr/include/boost/lib/libboost_system.a
/usr/include/boost/lib/libboost_system.so.1.46.1
/usr/lib/lib/libboost_system.so
/usr/lib/lib/libboost_system.a
/usr/lib/lib/libboost_system.so.1.46.1
/usr/local/include/boost_1_46_1/bin.v2/libs/system/build/gcc-4.4.3/release/link-static/threading-multi/libboost_system.a
/usr/local/include/boost_1_46_1/bin.v2/libs/system/build/gcc-4.4.3/release/threading-multi/libboost_system.so.1.46.1
/usr/local/lib/libboost_system.so
/usr/local/lib/libboost_system.a
/usr/local/lib/libboost_system.so.1.46.1
/root/tmp/boost_1_46_1/bin.v2/libs/system/build/gcc-4.4.3/release/link-static/threading-multi/libboost_system.a
/root/tmp/boost_1_46_1/bin.v2/libs/system/build/gcc-4.4.3/release/threading-multi/libboost_system.so.1.46.1

为什么这些文件位于 /usr/lib/lib 中?这是一个问题吗?

和 ls -l /usr/lib/lib | grep boost_system

ls -l /usr/lib/lib | grep boost_system
-rw-r--r-- 1 root root   21574 2011-05-09 15:15 libboost_system.a
lrwxrwxrwx 1 root root      25 2011-05-09 15:15 libboost_system.so -> libboost_system.so.1.46.1
-rwxr-xr-x 1 root root   20053 2011-05-09 15:15 libboost_system.so.1.46.1

atm 我的 makefile 看起来像

LIBPATH=-I/usr/local/include/cpp-netlib 
LIBS=$(LIBPATH) -lboost_system  -lboost_filesystem -lboost_thread -lpthread 

LD=g++ -g 
CPP=g++ -c -g $(LIBS)

P=.
OBJ=$(P)/tmp/main.o $(P)/tmp/CLink.o $(P)/tmp/CFetcher.o

main:   $(OBJ); $(LD) $(OBJ) $(LIBS) -o $@


$(P)/tmp/CLink.o:   $(P)/src/CLink.cpp $(P)/include/CLink.h; $(CPP) -c $< -o $@
$(P)/tmp/CFetcher.o:    $(P)/src/CFetcher.cpp $(P)/include/CFetcher.h; $(CPP) -c $< -o $@
$(P)/tmp/main.o:    $(P)/src/main.cpp $(P)/include/CLink.h $(P)/include/CFetcher.h ; $(CPP) -c $< -o $@

all:
    touch $(P)/tmp/*.o;
    touch main;
    rm -f $(P)/tmp/*.o;
    rm -f main;
    make main;

编译器输出是谎言

g++ -c -g -I/usr/local/include/cpp-netlib  -lboost_system  -lboost_filesystem -lboost_thread -lpthread  -c src/main.cpp -o tmp/main.o
g++ -c -g -I/usr/local/include/cpp-netlib  -lboost_system  -lboost_filesystem -lboost_thread -lpthread  -c src/CLink.cpp -o tmp/CLink.o
g++ -c -g -I/usr/local/include/cpp-netlib  -lboost_system  -lboost_filesystem -lboost_thread -lpthread  -c src/CFetcher.cpp -o tmp/CFetcher.o
g++ -g  ./tmp/main.o ./tmp/CLink.o ./tmp/CFetcher.o -I/usr/local/include/cpp-netlib  -lboost_system  -lboost_filesystem -lboost_thread -lpthread  -o main

所以对我来说一切看起来都不错但是当我尝试运行程序时

./main

./main: error while loading shared libraries: libboost_system.so.1.46.1: cannot open shared object file: No such file or directory

[SOLVED] created symlinks from /usr/lib/lib/* to /usr/lib*

[UPDATE 3] NEW VERSION:

Ok, I think I fixed something

use find / -name "libboost_system.*"
outout was

/usr/include/boost/lib/libboost_system.so
/usr/include/boost/lib/libboost_system.a
/usr/include/boost/lib/libboost_system.so.1.46.1
/usr/lib/lib/libboost_system.so
/usr/lib/lib/libboost_system.a
/usr/lib/lib/libboost_system.so.1.46.1
/usr/local/include/boost_1_46_1/bin.v2/libs/system/build/gcc-4.4.3/release/link-static/threading-multi/libboost_system.a
/usr/local/include/boost_1_46_1/bin.v2/libs/system/build/gcc-4.4.3/release/threading-multi/libboost_system.so.1.46.1
/usr/local/lib/libboost_system.so
/usr/local/lib/libboost_system.a
/usr/local/lib/libboost_system.so.1.46.1
/root/tmp/boost_1_46_1/bin.v2/libs/system/build/gcc-4.4.3/release/link-static/threading-multi/libboost_system.a
/root/tmp/boost_1_46_1/bin.v2/libs/system/build/gcc-4.4.3/release/threading-multi/libboost_system.so.1.46.1

why are these files in /usr/lib/lib ? and is it a problem ?

and the ls -l /usr/lib/lib | grep boost_system

ls -l /usr/lib/lib | grep boost_system
-rw-r--r-- 1 root root   21574 2011-05-09 15:15 libboost_system.a
lrwxrwxrwx 1 root root      25 2011-05-09 15:15 libboost_system.so -> libboost_system.so.1.46.1
-rwxr-xr-x 1 root root   20053 2011-05-09 15:15 libboost_system.so.1.46.1

atm my makefile looks like

LIBPATH=-I/usr/local/include/cpp-netlib 
LIBS=$(LIBPATH) -lboost_system  -lboost_filesystem -lboost_thread -lpthread 

LD=g++ -g 
CPP=g++ -c -g $(LIBS)

P=.
OBJ=$(P)/tmp/main.o $(P)/tmp/CLink.o $(P)/tmp/CFetcher.o

main:   $(OBJ); $(LD) $(OBJ) $(LIBS) -o $@


$(P)/tmp/CLink.o:   $(P)/src/CLink.cpp $(P)/include/CLink.h; $(CPP) -c 
lt; -o $@
$(P)/tmp/CFetcher.o:    $(P)/src/CFetcher.cpp $(P)/include/CFetcher.h; $(CPP) -c 
lt; -o $@
$(P)/tmp/main.o:    $(P)/src/main.cpp $(P)/include/CLink.h $(P)/include/CFetcher.h ; $(CPP) -c 
lt; -o $@

all:
    touch $(P)/tmp/*.o;
    touch main;
    rm -f $(P)/tmp/*.o;
    rm -f main;
    make main;

The Compiler output is lie

g++ -c -g -I/usr/local/include/cpp-netlib  -lboost_system  -lboost_filesystem -lboost_thread -lpthread  -c src/main.cpp -o tmp/main.o
g++ -c -g -I/usr/local/include/cpp-netlib  -lboost_system  -lboost_filesystem -lboost_thread -lpthread  -c src/CLink.cpp -o tmp/CLink.o
g++ -c -g -I/usr/local/include/cpp-netlib  -lboost_system  -lboost_filesystem -lboost_thread -lpthread  -c src/CFetcher.cpp -o tmp/CFetcher.o
g++ -g  ./tmp/main.o ./tmp/CLink.o ./tmp/CFetcher.o -I/usr/local/include/cpp-netlib  -lboost_system  -lboost_filesystem -lboost_thread -lpthread  -o main

So for me all looks nice but when i try to run the program

./main

./main: error while loading shared libraries: libboost_system.so.1.46.1: cannot open shared object file: No such file or directory

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

嘿哥们儿 2024-11-12 20:46:08
  1. -l 标志必须位于链接器命令行上的源文件之后

    是的,这意味着您必须将 LD 定义拆分为 LDLIBS,将所有 -L-l 标志,并将链接命令更改为:

    $(LD) $(OBJ) $(LIBS) -o $@

  2. 库 (.so< /code>(动态)或 .a(静态))文件必须与标头版本相同。虽然 /usr/local/include/boost_1_46_1/ 中安装了 boost 1.46.1 标头,但相应的库文件似乎根本没有安装。唯一安装的库是 /usr/lib 中的版本 1.40.0,因此链接器会找到这些库(默认情况下会搜索 /usr/lib 即使您没有包括 -L/usr/lib 标志),但它们不包含 1.46.1 所期望的符号。

    请注意,当链接到共享库时(在 Linux 中强烈建议使用共享库),链接器会查找扩展名为 .so 的文件,但这通常是指向具有添加版本的文件的符号链接后缀,链接器读取它并将目标名称记录在二进制文件中。这样,针对 .1.40 编译的程序将在安装 1.46 后继续工作,因为 libboost*.so.1.40.0 可能(并且必须)在 .so< 之后保留/code> 重定向到 1.46.1 版本。

    甚至应该可以像这样安装:

    /usr/local/lib/boost_1_46_1/libboost_system-mt.so -> /usr/local/lib/libboost_system-mt.so.1.46
    /usr/local/lib/libboost_system-mt.so.1.46 -> /usr/local/lib/libboost_system-mt.so.1.46.1
    /usr/local/lib/libboost_system-mt.so.1.46.1
    

    并使用-L/usr/local/lib/boost_1_46_1进行编译,尽管我目前找不到任何可以确认这一点的包。这样,您就可以安装多个版本的开发文件,并使用显式的 -I-L 标志在它们之间切换,而动态链接器仍然会找到运行时文件,为此只查看 /usr/local/lib/usr/lib/lib (可以在 /etc/ 中配置) ld.so.conf,但这是默认设置)。

  1. The -l flags must come after the source files on linker command-line.

    Yes, that means you'll have to split the LD definition to LD and LIBS, put all the -L and -l flags in the later and change the link command to:

    $(LD) $(OBJ) $(LIBS) -o $@

  2. The library (.so (dynamic) or .a (static)) files have to be the same version as the headers. While there are boost 1.46.1 headers installed in /usr/local/include/boost_1_46_1/, the corresponding library files don't seem to be installed at all. The only installed libraries are version 1.40.0 in /usr/lib, so the linker finds those (/usr/lib would be searched by default even if you didn't include the -L/usr/lib flag), but they don't contain the symbols expected by 1.46.1.

    Note that when linking against shared library (using shared libraries is strongly recommended in Linux), the linker looks for the file with .so extension, but that is usually symlink to a file with added version suffix and the linker reads it and records the target name in the binary. That way programs compiled against the .1.40 will continue to work when 1.46 is installed, because the libboost*.so.1.40.0 may (and have to) stay around after the .so is redirected to the 1.46.1 version.

    It should be even possible to install like:

    /usr/local/lib/boost_1_46_1/libboost_system-mt.so -> /usr/local/lib/libboost_system-mt.so.1.46
    /usr/local/lib/libboost_system-mt.so.1.46 -> /usr/local/lib/libboost_system-mt.so.1.46.1
    /usr/local/lib/libboost_system-mt.so.1.46.1
    

    and compile using -L/usr/local/lib/boost_1_46_1, though I currently can't find any package that would do it to confirm this. This way you could have development files for multiple versions installed and switch between them using explicit -I and -L flags while dynamic linker would still find the runtime files, for which it only looks in /usr/local/lib, /usr/lib and /lib (it can be configured in /etc/ld.so.conf, but that's the default).

热鲨 2024-11-12 20:46:08

使用 strace 执行您的应用程序。这将显示您的应用程序正在寻找您的 boost 库的位置。就我而言,应用程序正在 /usr/lib/x86_64-linux-gnu 中查找实际位置为 /usr/lib/lib 的 boost 库。在我的例子中,一个简单的导出语句添加了 boost 共享库的路径LD_LIBRARY_PATH=/usr/lib/lib,效果很好。

strace 的输出

open("/usr/lib/x86_64-linux-gnu/libboost_system.so.1.46.1", O_RDONLY) = -1 ENOENT (No such file or directory)
exit_group(127)                         = ?

Execute your application with strace. This will show the location were you app is looking for your boost libs. In my case an app was looking in /usr/lib/x86_64-linux-gnu for boost libs where the actual location was /usr/lib/lib. A simple export statement adding the paths for the boost shared libs in my case LD_LIBRARY_PATH=/usr/lib/lib worked a treat.

output from strace

open("/usr/lib/x86_64-linux-gnu/libboost_system.so.1.46.1", O_RDONLY) = -1 ENOENT (No such file or directory)
exit_group(127)                         = ?
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文