简体   繁体   English

链接到共享的 boost 库让人头疼

[英]Linking to shared boost library giving headaches

I have an issue which sounds annoyingly simple, but I feel I've tried everything to resolve it and I'm out of ideas.我有一个听起来很简单的问题,但我觉得我已经尝试了一切来解决它,但我没有想法。

I have a program I wrote which uses boost/program_options.hpp using the include statement我有一个我写的程序,它使用包含语句使用 boost/program_options.hpp

#include <boost/program_options.hpp>

This program works on my laptop and now I am trying to put it onto a server where I don't have sudo privileges.这个程序在我的笔记本电脑上运行,现在我试图把它放到我没有 sudo 权限的服务器上。 On my laptop, where the whole thing works I have boost versions 1.56 and 1.58 and on the server I found 1.53.0.在我的笔记本电脑上,我有 1.56 和 1.58 的增强版,在我的服务器上我找到了 1.53.0。 I didn't install or build this though.我没有安装或构建这个。

The shared library file that exists on the server is: /usr/lib64/libboost_program_options.so.1.53.0服务器上存在的共享库文件为:/usr/lib64/libboost_program_options.so.1.53.0

Running ldd on that gives me the output:运行 ldd 给我输出:

 ldd /usr/lib64/libboost_program_options.so.1.53.0
 linux-vdso.so.1 =>  (0x00007ffc54a63000)
 libstdc++.so.6 => /lib64/libstdc++.so.6 (0x00007fc0dcad8000)
 libm.so.6 => /lib64/libm.so.6 (0x00007fc0dc7d5000)
 libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x00007fc0dc5bf000)
 libc.so.6 => /lib64/libc.so.6 (0x00007fc0dc1fe000)
 /lib64/ld-linux-x86-64.so.2 (0x00007fc0dd071000)

Which I assume means it's found all its dependencies.我认为这意味着它找到了所有依赖项。

I have made a symbolic link to my home directory to create a libboost_program_options.so link, which I guess means the -lboost_program_options linker flag should work.我已经建立了一个指向我的主目录的符号链接来创建一个 libboost_program_options.so 链接,我猜这意味着 -lboost_program_options 链接器标志应该可以工作。

The way I compile is by:我编译的方式是:

g++ -L/home/homeDir code.cpp -o code.o -std=c++11 -Wall -lboost_program_options

And all I get is:我得到的只是:

fatal error: boost/program_options.hpp: No such file or directory
 #include "boost/program_options.hpp"
                                     ^
compilation terminated.

I've tried this with quotes and <>, and without "boost/" etc, but I always get the same complaint.我已经用引号和 <> 尝试过这个,没有“boost/”等,但我总是得到同样的抱怨。 I assume this means that it finds the library as there is no complaint about the -lboost_program_options flag?我认为这意味着它找到了库,因为对 -lboost_program_options 标志没有任何抱怨?

While it works on my machine, I may not be using the shared program options library at all.虽然它在我的机器上工作,但我可能根本没有使用共享程序选项库。 On my laptop I have both a static version of libboost_program_options in my library path which it may be using, and the program_options.hpp header outside of a library which may be in my include path.在我的笔记本电脑上,我的库路径中既有静态版本的 libboost_program_options 可能正在使用,也有库外的 program_options.hpp 标头,它可能在我的包含路径中。 I feel like I should be able to use the shared library that's on the server and not annoy the server admin for the 5th time (things work really slowly with these things here).我觉得我应该能够使用服务器上的共享库,而不是第 5 次惹恼服务器管理员(这些东西在这里工作真的很慢)。

I'm sorry if this is my oversight.如果这是我的疏忽,我很抱歉。 I'm fairly new to boost, but I feel like I've tried everything to resolve this myself at the moment.我对提升还很陌生,但我觉得我现在已经尝试了一切来解决这个问题。

I'd be happy with any suggestions as to how I could change this... or if I'm just being a bit stupid with using shared libraries.我很乐意就如何改变这一点提出任何建议......或者如果我只是在使用共享库时有点愚蠢。

Thanks in advance.提前致谢。

EDIT: After more research I feel like I'm just getting confused between static and shared libraries.编辑:经过更多研究,我觉得我只是在静态库和共享库之间感到困惑。 I'm trying to link a shared library at compile time, which I guess doesn't make sense.我试图在编译时链接一个共享库,我想这没有意义。 Also including the header file of something which should not be linked at compile time makes little sense.还包括在编译时不应该链接的头文件是没有意义的。 My code is clearly designed for the static library.我的代码显然是为静态库设计的。

The error message is produced by the pre-compiler which does not find the Boost header file (as it says in the error message).错误消息是由未找到 Boost 头文件的预编译器生成的(如错误消息中所述)。 You need to set the correct include path ( -I... ) where the Boost library header files are found, obviously they are not under /usr/include .您需要在找到 Boost 库头文件的位置设置正确的包含路径( -I... ),显然它们不在/usr/include

Path to the Boost libraries ( -L... ) must be specified accordingly.必须相应地指定 Boost 库 ( -L... ) 的路径。

Finally: If you are linking against the Boost shared libraries on your system, then you should use the same version of Boost as installed on the server.最后:如果您要链接系统上的 Boost 共享库,那么您应该使用与服务器上安装的 Boost 版本相同的版本。 Otherwise, link against the static libraries, this may make you executable larger, but it will run on any server, regardless of the Boost version installed there (even none).否则,链接静态库,这可能会使您的可执行文件更大,但它会在任何服务器上运行,无论那里安装的 Boost 版本如何(甚至没有)。

sudo apt install libboost-program-options-dev

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM