gpt4 book ai didi

c++ - 如果同时存在共享库和动态库,则链接器将首选哪个库?

转载 作者:行者123 更新时间:2023-12-02 10:22:42 25 4
gpt4 key购买 nike

相同的选项可用于静态链接和动态链接库。
$(CC)$(CFLAGS)-L $(PATH_TO_LIB)-l $(库名)-o输出文件名

如果我的PATH_TO_LIB同时包含.a和.so文件,链接器将首选哪一个文件?

最佳答案

如果链接器是ld的变体,则它将首选共享对象而不是存档。从-l标志的documentation中,强调我的:

-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.

On systems which support shared libraries, ld may also search for files other than libnamespec.a. Specifically, on ELF and SunOS systems, ld will search a directory for a library called libnamespec.so before searching for one called libnamespec.a. (By convention, a .so extension indicates a shared library.) Note that this behavior does not apply to :filename, which always specifies a file called filename.

关于c++ - 如果同时存在共享库和动态库,则链接器将首选哪个库?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59393235/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com