gpt4 book ai didi

c++ - 外部库 boost 版本问题

转载 作者:行者123 更新时间:2023-11-28 05:38:28 25 4
gpt4 key购买 nike

我有一个我参与的项目的外部库,它是针对 boost 1.55 编译的;我已经转移到另一个需要使用这个库的项目,但当前系统正在使用 boost 1.58

当我链接到库时,它提示它缺少对 boost 1.55 库的引用。我要链接的库是使用以下 find_package 命令编译的:

find_package( Boost 1.55 COMPONENTS ... REQUIRED )

我知道 CMake 有一个 min 命令,但我不确定这是否允许我在当前运行 1.58 1.55 编译的库强>.

任何关于如何编译这个外部库以便它使用与 1.55 兼容的任何版本的 boost 的任何建议都将不胜感激!

尝试寻找 boost 的新程序的 find_package 命令):

find_package( Boost 1.55 COMPONENTS system filesystem chrono regex thread date_time REQUIRED )

新程序所在的系统的 boost 是 1.58 而不是 1.55,因此输出如下:

-- Boost version: 1.58.0
-- Found the following Boost libraries:
-- system
-- filesystem
-- chrono
-- regex
-- thread
-- date_time
-- atomic

compile 对 1.58 工作正常,只有当新程序链接到库(针对 1.55 编译)时,它才会提示无法找到 boost 1.55 库(见下文) .

链接输出:(新程序链接到库)

/usr/bin/ld: warning: libboost_system.so.1.55.0, needed by library.so, not found (try using -rpath or -rpath-link)
/usr/bin/ld: warning: libboost_filesystem.so.1.55.0, needed by library.so, not found (try using -rpath or -rpath-link)
/usr/bin/ld: warning: libboost_chrono.so.1.55.0, needed by library.so, not found (try using -rpath or -rpath-link)
/usr/bin/ld: warning: libboost_regex.so.1.55.0, needed by library.so, not found (try using -rpath or -rpath-link)
/usr/bin/ld: warning: libboost_thread.so.1.55.0, needed by library.so, not found (try using -rpath or -rpath-link)
/usr/bin/ld: warning: libboost_date_time.so.1.55.0, needed by library.so, not found (try using -rpath or -rpath-link)

最佳答案

find_package( Boost 1.55 COMPONENTS ... REQUIRED )

如果它找到任何版本的 Boost >= 1.55 就会满意。

find_package( Boost 1.55 EXACT COMPONENTS ... REQUIRED )

只会对 Boost 1.55 感到满意。

因此,如果您只是使用相同的 CMakeLists 重建库在有 Boost 1.58 的情况下应该不错。

稍后

I am trying to come up with a method that I can compile the library once (say using boost 1.55) in a manner so that if on another system that is running a new version of boost say 1.58; won't complain about not having the 1.55 boost library when it has the 1.58 version of the boost libraries available

你不能那样做:

find_package( Boost 1.55 COMPONENTS ... REQUIRED )

将允许您使用 boost 1.55 或更高版本构建库但是您构建的库将动态链接到实际上找到的 boost 版本,并且动态链接已烘焙通过操作系统加载程序的信息进入二进制文件。

因此,如果您将该库带到某个没有 boost 1.55 的系统您将遇到链接错误,例如您在尝试链接图书馆和其他任何东西。

遗憾的是,您必须在 boost 1.58 存在的情况下构建此库将其与 boost 1.58 系统上的任何内容链接。

关于c++ - 外部库 boost 版本问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37690272/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com