简体   繁体   English

如果 GCC 只找到一个静态库而不是动态库,它是否诉诸静态链接找到的文件?

[英]If GCC only finds a static library and not a dynamic one, does it resort to static linking the found file?

Please consider the following command:请考虑以下命令:

gcc myfile.c -o myapp.exe -Lmydir -lmylib

mydir inclues the following file: mydir包括以下文件:

`libmylib.a`

I know that by default, gcc wants to do dyanmic linking.我知道默认情况下, gcc想要进行动态链接。 However, as you can see it does not find a libmylib.so dynamic library, only a libmylib.a static one.但是,如您所见,它没有找到libmylib.so动态库,只有libmylib.a静态库。

Does that mean that gcc will statically link libmylib.a into the result executable?这是否意味着gcc会将libmylib.a静态链接到结果可执行文件中?

This behavior is up to the linker, not GCC.这种行为取决于链接器,而不是 GCC。 Standard linker behavior is to try a dynamic library then a static one in each path component of the link search path.标准链接器行为是先尝试动态库,然后在链接搜索路径的每个路径组件中尝试静态库。 For example, if the first directory searched has only a static library by the name, the second directory will not be searched at all, even if it has a dynamic one.例如,如果搜索的第一个目录只有一个静态库名称,则根本不会搜索第二个目录,即使它有一个动态的。 As such, for normal user expectations to work correctly, corresponding dynamic and static versions of the same library need to be placed in the identical location.因此,为了正常用户期望正常工作,同一库的相应动态和静态版本需要放置在相同的位置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM