使用必要的链接安装共享的导入库 [英] install shared imported library with necessary links

查看:87
本文介绍了使用必要的链接安装共享的导入库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此问题询问如何使用已导入而不是由当前项目构建的cmake安装共享库:

This question asks how to install a shared library with cmake which has been imported rather than being built by the current project:

我可以安装共享的导入库吗?

要重复问题:

add_library(libfoobar SHARED IMPORTED)
# this install command is illegal
install(TARGET libfoobar LIBRARY DESTINATION "${RPMBUILDROOT}${LIBDIR}")

此字符被提出为[< a href = https://gitlab.kitware.com/cmake/cmake/issues/14311|issue] rel = nofollow noreferrer> https://gitlab.kitware.com/cmake/cmake/issues/14311 |问题] 与已经关闭的cmake一起有效地解决了,将无法解决。出于相当合理的理由,cmake对导入的目标不了解足够多,无法可靠地安装它。

This was raised as a [https://gitlab.kitware.com/cmake/cmake/issues/14311|issue] with cmake that has been closed, effectively with a resolution of will not fix. The grounds are, quite reasonably, that cmake does not know enough about an imported target to reliably install it.

对于这个问题,有一点没有回答,那就是install(TARGET )会自动在GNU / Linux和需要此功能的其他类似unix的平台上创建从libfoo.so到libfoo.so.major和libfoo.so.minor版本的链接。

One point the answer to that question misses is that install(TARGET) will automagically create links from libfoo.so to libfoo.so.major and libfoo.so.minor version on GNU/Linux and other unix-like platforms where this is required.

是否有一种方法可以劫持cmake,将其视为由项目构建的自定义目标,还是说服它创建那些链接?
类似:

add_library(libfoobar SHARED IMPORTED)

#? add_custom_target(X libfoobar) 
install(TARGET X LIBRARY DESTINATION "${RPMBUILDROOT}${LIBDIR}")

执行此操作的规范方法是什么?

What is a canonical way to do this?

推荐答案

当CMake构建库时,它是 CMake ,谁为其分配Soversion号(根据项目设置)。

When a library is built by CMake, it is CMake who assigns soversion numbers to it (according to project's settings).

当CMake不构建库时, CMake不知道soversion ,因此它无法为您创建符号链接。

When a library isn't built by CMake, CMake doesn't know soversion, so it cannot create symlinks for you.

如果您担心CMake实际上安装了符号链接而不是文件,请在安装前解析符号链接,例如在该问题

If you bother about that CMake actually installs symlink instead of file, resolve symlinks before installing, like in that question.

嗯,您可以要求CMake对库进行猜测转换(例如,通过resolvi ng符号链接并检查其名称)。但是为什么需要符号链接?

Well, you may ask CMake to guess soversion of the library (e.g. by resolving symlinks and checking their names). But why you ever need symlinks?

soversion符号链接的主要目的是解决与将来库的更新的兼容性问题。但是,只有在由项目创建者创建的库安装了库之后,才可以进行更新。

The main purpose of soversion symlink is to resolve compatibility issues with the future library's updates. But updates are possible only when the library is installed by the project who creates it.

如果您的项目安装了由 other生产的库项目,您不太可能希望支持 local 库安装的更新。因此,您不需要支持soversions。

If your project installs library produced by other project, it is unlikely that you want to support updates for the local library's installation. So there is no needs for you to support soversions.

这篇关于使用必要的链接安装共享的导入库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆