我们为什么要在构建库时设置符号链接?

时间:2022-09-11 12:10:40

I have a question related to building a library in C++ for multiple platforms. I notice that many libraries expect a "symbolic link". With CMake, the symbolic link is done by the following codes:

我有一个问题与在C ++中为多个平台构建库有关。我注意到许多图书馆都希望有一个“符号链接”。使用CMake,符号链接由以下代码完成:

set_target_properties({library_name}, PROPERTIES VERSION, ${library_string_version} SOVERSION {library_string_shortversion})

I cannot understand why symbolic link is necessary for a library. Moreover, it seems to me symbolic link is always related to the version of the library, and are there any relationships between them? Thanks!

我无法理解为什么图书馆需要符号链接。而且,在我看来,符号链接总是与库的版本有关,它们之间是否有任何关系?谢谢!

2 个解决方案

#1


2  

The advantage of using a symbolic link is that you can easily update the library, with a new version, maintaining a consistent name, while at the same time having the version in the library name accessible. So applications can always link against the same name if even if you update it. Only when they need a specific version, they can link to that instead. Also it makes it easier to move it around if need be, because the application doesn't need to know where it comes from.

使用符号链接的优点是,您可以使用新版本轻松更新库,维护一致的名称,同时可以访问库名称中的版本。因此,即使您更新应用程序,也始终可以链接相同的名称。只有当他们需要特定版本时,他们才能链接到该版本。此外,如果需要,它可以更容易移动它,因为应用程序不需要知道它来自何处。

I often wish I had symbolic links in MS Windows as well, as it makes life much easier.

我经常希望我在MS Windows中也有符号链接,因为它使生活更容易。

#2


2  

It allows for side-by-side versioning of the library.

它允许对库进行并排版本控制。

libfoo.so -> libfoo.2.so
libfoo.1.so -> libfoo.1.23.so
libfoo.1.23.so
libfoo.2.so -> libfoo.2.1.so
libfoo.2.1.so

This way, libfoo.so is always the latest version. If you know, (for compatibility reasons) that you need version 1 and not version 2, you can link against libfoo.1.so, and always have the latest v1 version.

这样,libfoo.so始终是最新版本。如果您知道(出于兼容性原因)您需要版本1而不是版本2,则可以链接libfoo.1.so,并始终拥有最新的v1版本。

#1


2  

The advantage of using a symbolic link is that you can easily update the library, with a new version, maintaining a consistent name, while at the same time having the version in the library name accessible. So applications can always link against the same name if even if you update it. Only when they need a specific version, they can link to that instead. Also it makes it easier to move it around if need be, because the application doesn't need to know where it comes from.

使用符号链接的优点是,您可以使用新版本轻松更新库,维护一致的名称,同时可以访问库名称中的版本。因此,即使您更新应用程序,也始终可以链接相同的名称。只有当他们需要特定版本时,他们才能链接到该版本。此外,如果需要,它可以更容易移动它,因为应用程序不需要知道它来自何处。

I often wish I had symbolic links in MS Windows as well, as it makes life much easier.

我经常希望我在MS Windows中也有符号链接,因为它使生活更容易。

#2


2  

It allows for side-by-side versioning of the library.

它允许对库进行并排版本控制。

libfoo.so -> libfoo.2.so
libfoo.1.so -> libfoo.1.23.so
libfoo.1.23.so
libfoo.2.so -> libfoo.2.1.so
libfoo.2.1.so

This way, libfoo.so is always the latest version. If you know, (for compatibility reasons) that you need version 1 and not version 2, you can link against libfoo.1.so, and always have the latest v1 version.

这样,libfoo.so始终是最新版本。如果您知道(出于兼容性原因)您需要版本1而不是版本2,则可以链接libfoo.1.so,并始终拥有最新的v1版本。