外部库增强版本问题

时间:2016-06-07 22:12:27

标签: c++ boost linker

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

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

find_package( Boost 1.55 COMPONENTS ... REQUIRED )

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

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

尝试查找提升的新程序的

find_package命令:

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)

1 个答案:

答案 0 :(得分:1)

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),以便在另一个正在运行的系统上运行   一个新版本的提升说1.58;不会抱怨没有1.55提升   库有可用的1.58版本的增强库

你做不到:

find_package( Boost 1.55 COMPONENTS ... REQUIRED )

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

因此,如果您将该库带到某些系统,其中不存在boost 1.55 您将获得链接错误,例如您在尝试链接时看到的错误 图书馆还有别的东西。

令人遗憾的是,你必须在boost 1.58的存在下构建这个库 将它与系统上的任何东西都联系起来,这个系统处于提升1.58。