如何在GCC中链接到共享库的特定版本

时间:2021-03-26 07:00:46

I'm compiling some code which uses libcurl on a Debian Linux system. My dev machine is running Debian 5 but I want the binary to be usable on older Debian 4 systems too.

我正在编译一些在Debian Linux系统上使用libcurl的代码。我的开发机器正在运行Debian 5,但是我希望二进制文件也可以在旧的Debian 4系统上使用。

I find that if I specify -lcurl it will link to libcurl.so.4 but Debian 4 systems only have libcurl.so.3

我发现如果我指定-lcurl它会链接到libcurl.so。但是Debian 4系统只有libcurl. so3。

Is there some way I can tell GCC to link to either libcurl.so.3 (which exists in both Debian 4 and 5) or just libcurl.so so it will use whatever version is available ?

我是否可以告诉GCC链接到libcurl.so。3(在Debian 4和5中都存在)或只是libcurl。所以它会使用任何可用的版本?

4 个解决方案

#1


23  

You can pass the actual .so file instead of -l on the linker command line, and it ought to do what you want.

您可以在链接器命令行上传递实际的.so文件而不是-l,它应该执行您想要的操作。

#2


57  

Instead of using "-lcurl" use "-l:libcurl.so.3" And ofcourse also use "-L _installed_path_"

而不是使用"-lcurl"使用"-l:libcurl.so。3"当然还有"-L _installed_path_"

#3


1  

How about creating a symlink local to your project that links to .3, then you can just use -L at compile time. I'm not sure if you'd get a name conflict though, but you could always call it libcurl-old.so just in case.

如何创建一个链接到.3的项目的本地符号链接,然后您可以在编译时使用-L。我不确定你会不会有名字冲突,但你可以叫它libcurl-old。所以以防。

#4


0  

I think the correct way to do that will be to use the --filter and --auxiliary flags of the linker.

我认为正确的方法是使用链接器的-filter和-辅标志。

They are not very documented, but should allow you to load symbols from different versions of the same library according to the machine you are installed on.

它们没有详细的文档说明,但是应该允许您根据安装的机器从同一库的不同版本加载符号。

#1


23  

You can pass the actual .so file instead of -l on the linker command line, and it ought to do what you want.

您可以在链接器命令行上传递实际的.so文件而不是-l,它应该执行您想要的操作。

#2


57  

Instead of using "-lcurl" use "-l:libcurl.so.3" And ofcourse also use "-L _installed_path_"

而不是使用"-lcurl"使用"-l:libcurl.so。3"当然还有"-L _installed_path_"

#3


1  

How about creating a symlink local to your project that links to .3, then you can just use -L at compile time. I'm not sure if you'd get a name conflict though, but you could always call it libcurl-old.so just in case.

如何创建一个链接到.3的项目的本地符号链接,然后您可以在编译时使用-L。我不确定你会不会有名字冲突,但你可以叫它libcurl-old。所以以防。

#4


0  

I think the correct way to do that will be to use the --filter and --auxiliary flags of the linker.

我认为正确的方法是使用链接器的-filter和-辅标志。

They are not very documented, but should allow you to load symbols from different versions of the same library according to the machine you are installed on.

它们没有详细的文档说明,但是应该允许您根据安装的机器从同一库的不同版本加载符号。