链接动态库时编译器选项“-l”的含义是什么?
What is the meaning of compiler option "-l" in linking dynamic libraries?
链接动态库的时候感觉很乱。虽然我使用 -L$(DIR) -l$(LIB)
指定库及其目录,但 ldd
总是告诉我这个 .so
来自 LD_LIBRARY_PATH
.
所以,我想知道-l$(LIB)
的唯一作用是帮助编译器检查函数声明是否匹配吗?
SO, I wonder if the only effect of -l$(LIB)
is to help compiler check whether the function declaration is match?
差不多是的,这就是目的。
即使链接到运行时动态加载的库,链接器也需要解析其中定义的函数。
在这种情况下,将创建一个存根库来解析函数调用。这是使用 -l
选项提供的。
链接动态库的时候感觉很乱。虽然我使用 -L$(DIR) -l$(LIB)
指定库及其目录,但 ldd
总是告诉我这个 .so
来自 LD_LIBRARY_PATH
.
所以,我想知道-l$(LIB)
的唯一作用是帮助编译器检查函数声明是否匹配吗?
SO, I wonder if the only effect of
-l$(LIB)
is to help compiler check whether the function declaration is match?
差不多是的,这就是目的。
即使链接到运行时动态加载的库,链接器也需要解析其中定义的函数。
在这种情况下,将创建一个存根库来解析函数调用。这是使用 -l
选项提供的。