gcc链接器在选择的库路径中找到.so和.a。 [英] gcc linker finding both .so and .a in the library path which is chosen?

查看:347
本文介绍了gcc链接器在选择的库路径中找到.so和.a。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我运行

If I run

gcc a.c -L /usr/lib -lexpat 

libexpat.a和libexpat.so都在/ usr lib中,链接器使用哪一个?

and both libexpat.a and libexpat.so are in /usr lib which one is used by the linker?

推荐答案

默认情况下,共享库(.so)将被选中。

By default the shared library (.so) will be chosen.

如果你想改变这个行为,可以使用 -static gcc选项

If you want to change this behavior, -static gcc option may be used


-static

-static

在支持动态链接的系统上,这样可以避免将
链接到共享库。在其他
系统上,此选项不起作用。

On systems that support dynamic linking, this prevents linking with the shared libraries. On other systems, this option has no effect.

这篇关于gcc链接器在选择的库路径中找到.so和.a。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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