如何指定链接时使用的库版本? [英] How to specify the library version to use at link time?

查看:1063
本文介绍了如何指定链接时使用的库版本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下问题如何应用程序在运行时是否解析了不同版本的共享库?,我想知道如何在链接命令行上指定要使用哪个版本的库?

Following question How do applications resolve to different versions of shared libraries at run time?, I wondered how to specify on the link command line which version of the library to use?

假设我有

Let's say I have

libmy.so.1.0
libmy.so.1    -> libmy.so.1.0
libmy.so.2.0
libmy.so.2    -> libmy.so.2.0
libmy.so      -> libmy.so.2

指定与可执行文件链接的库的常用方法不会显示版本使用。此外,人们很可能想要链接最新的版本。因此,大多数情况下,通常的系统都可以正常工作。

The usual way to specify the library to link with the executable does not show the version to use. Furthermore, it is very likely that one wants to link with the most recent version. Thus the usual line works fine in most cases.

gcc app.o -lmy -o app

链接 app 的命令行应该使用版本1 library?

What is the command line to link app that should use version 1 of the library?

推荐答案

链接器也可以接受文件名

The linker is able to accept filenames too

gcc  app.o -l:libmy.so.1 -o app



man ld


-l namespec

-l namespec
--library=namespec
Add the archive or object file specified by namespec to the list of files to link. This option may be used any number of times. If namespec is of the form :filename, ld will search the library path for a file called filename, otherwise it will search the library path for a file called libnamespec.a.

我注意到旧版本不支持它,所以请检查 man ld -l <​​/ code>或 - library 选项。

I noticed that older versions do not support it, so check man ld -l or --library option on your system.

您也可以链接到提及其全名的文件

You could also link to the file mentioning its full name

gcc  app.o /mylibpath/libmy.so.1 -o app

这篇关于如何指定链接时使用的库版本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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