外部库Boost版本问题

External Library Boost Version Problems

本文关键字:问题 版本 Boost 外部      更新时间:2023-10-16

我在一个项目中有一个外部库,该库是根据boost 1.55编译的;我已经转到另一个需要使用此库的项目,但当前系统正在使用boost1.58

当我链接到该库时,它会抱怨它缺少boost1.55库的引用。我链接的库是使用以下find_package命令编译的:

find_package( Boost 1.55 COMPONENTS ... REQUIRED )

我知道CMake有一个min命令,但我不确定这是否允许我在当前运行1.58的机器上使用针对boost11.55编译的库。

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

find_package命令用于尝试查找boost的新程序):

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

新程序所在的系统的升压为1.58,而不是1.55,因此它输出以下内容:

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

编译在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的存在下,它应该是好的。

稍后

我正试图想出一种方法,可以编译一次库(比如使用boost 1.55),如果在另一个正在运行的系统上一个新版本的boost,比如1.58;不会抱怨没有1.55的增压当它有1.58版本的增强库可用时

你不能这么做:

find_package( Boost 1.55 COMPONENTS ... REQUIRED )

将允许您使用boost 1.55或更高版本构建库,但您构建的库将与事实上已经找到的boost版本,并且动态链接已经烘焙通过OS加载器的信息将其转换为二进制。

所以,如果你把这个库带到某个系统,那里没有boost 1.55当您尝试链接图书馆和其他任何东西。

遗憾的是,您将不得不在boost 1.58的存在下构建此库将其与升压1.58的系统上的任何东西联系起来。