I'm building my program on my computer, on which libtiff.so -> libtiff.so.5
. And then pushing the builds on another machine on which libtiff.so -> libtiff.so.4
.
我正在我的计算机上构建我的程序,libtiff.so - > libtiff.so.5。然后在libtiff.so - > libtiff.so.4上的另一台机器上推送构建版本。
At runtime, my program exists : « error while loading shared libraries: libtiff.so.5
: cannot open shared object file: No such file or directory ».
在运行时,我的程序存在:«加载共享库时出错:libtiff.so.5:无法打开共享对象文件:没有这样的文件或目录»。
I cannot upgrade the other machine, and I would like to avoid compiling on a virtual machine (with the same linux version than the executing machine). Therefore, I would like to force the compiler to use the libtiff.so.4
instead of libtiff.so.5
.
我无法升级其他机器,我想避免在虚拟机上编译(使用与执行机器相同的Linux版本)。因此,我想强制编译器使用libtiff.so.4而不是libtiff.so.5。
I have libtiff.so.4
installed on my computer (as well as libtiff.so.5
). How can I force the linkage with this version instead of the newer version. I thought about moving the libtiff.so -> libtiff.so.4
, but I'm afraid of breaking my system if it needs the latest version (apt-get purge libtiff5
gives an error because some other package needs it).
我在我的计算机上安装了libtiff.so.4(以及libtiff.so.5)。如何强制与此版本的链接而不是新版本。我想移动libtiff.so - > libtiff.so.4,但是如果它需要最新版本,我害怕破坏我的系统(apt-get purge libtiff5给出了一个错误,因为其他一些包需要它)。
Is it possible to link with an older (installed) version of a library? If yes, how? And is it harmfull to change the symbolic link of libtiff.so
to the older version? If not, will it solve my issue?
是否可以链接到较旧(已安装)的库版本?如果有,怎么样?将libtiff.so的符号链接更改为旧版本是否有害?如果没有,它会解决我的问题吗?
3 个解决方案
#1
2
You can use this syntax to link to a specific version of a library:
您可以使用此语法链接到库的特定版本:
gcc [other options] -l:libtiff.so.4
You do not need to specify a path; the usual directories are searched in order to find the library.
您不需要指定路径;搜索通常的目录以便找到库。
Note: as Michael Wild mentioned, you should have the header files for that version installed instead of the newest ones.
注意:正如Michael Wild所提到的,您应该安装该版本的头文件而不是最新版本。
#2
1
As others have mentioned, you can force the linker by specifying the full versioned name, or even the absolute path.
正如其他人所提到的,您可以通过指定完整版本名称甚至绝对路径来强制链接器。
However, I would strongly advice against doing so. The problem is, that the installed headers correspond to the newer version of the library. If there have been API/ABI-breaking changes between these library versions, the program might work, crash intermittently, or if you're lucky, not work at all.
但是,我强烈反对这样做。问题是,安装的标头对应于较新版本的库。如果这些库版本之间存在API / ABI断开的变化,程序可能会工作,间歇性崩溃,或者如果你很幸运,根本不工作。
Instead you should temporarily install the development package that corresponds to the libtiff.so.4 library. If on Debian/Ubuntu or similar, this would be the libtiff4-dev
package.
相反,您应该临时安装与libtiff.so.4库对应的开发包。如果在Debian / Ubuntu或类似的,这将是libtiff4-dev包。
#3
0
Specify the full path to the .so: instead of -ltiff
pass /lib64/libtiff.so.4
to the linker.
指定.so的完整路径:而不是-ltiff将/lib64/libtiff.so.4传递给链接器。
#1
2
You can use this syntax to link to a specific version of a library:
您可以使用此语法链接到库的特定版本:
gcc [other options] -l:libtiff.so.4
You do not need to specify a path; the usual directories are searched in order to find the library.
您不需要指定路径;搜索通常的目录以便找到库。
Note: as Michael Wild mentioned, you should have the header files for that version installed instead of the newest ones.
注意:正如Michael Wild所提到的,您应该安装该版本的头文件而不是最新版本。
#2
1
As others have mentioned, you can force the linker by specifying the full versioned name, or even the absolute path.
正如其他人所提到的,您可以通过指定完整版本名称甚至绝对路径来强制链接器。
However, I would strongly advice against doing so. The problem is, that the installed headers correspond to the newer version of the library. If there have been API/ABI-breaking changes between these library versions, the program might work, crash intermittently, or if you're lucky, not work at all.
但是,我强烈反对这样做。问题是,安装的标头对应于较新版本的库。如果这些库版本之间存在API / ABI断开的变化,程序可能会工作,间歇性崩溃,或者如果你很幸运,根本不工作。
Instead you should temporarily install the development package that corresponds to the libtiff.so.4 library. If on Debian/Ubuntu or similar, this would be the libtiff4-dev
package.
相反,您应该临时安装与libtiff.so.4库对应的开发包。如果在Debian / Ubuntu或类似的,这将是libtiff4-dev包。
#3
0
Specify the full path to the .so: instead of -ltiff
pass /lib64/libtiff.so.4
to the linker.
指定.so的完整路径:而不是-ltiff将/lib64/libtiff.so.4传递给链接器。