gcc 的 -ldl 参数是什么意思?

2013-04-27 17:22:15 +08:00
 rrfeng
情景:
编译安装 keepalived,需要 openssl-devel 的库

但是 openssl 也是编译安装的,安装目录是 /usr/local/openssl

keepalived configure 的时候,无论是
--libdir=/usr/local/openssl
还是
LDFLAGS="$LDFLAGS -L/usr/local/openssl" ;
或者指定 /usr/local/openssl/lib /usr/local/openssl/include 等目录

均提示 OpenSSL 库找不到。



最终在
LDFLAGS="-ldl" ./configure
的时候编译成功了,成功的自动找到了 openssl 中相关文件
11947 次点击
所在节点    问与答
2 条回复
wwwjfy
2013-04-27 17:53:30 +08:00
-llibrary
-l library
Search the library named library when linking. (The second alternative with the library as a separate argument is only for POSIX compliance and is not recommended.)

It makes a difference where in the command you write this option; the linker searches and processes libraries and object files in the order they are specified. Thus, foo.o -lz
bar.o searches library z after file foo.o but before bar.o. If bar.o refers to functions in z, those functions may not be loaded.

The linker searches a standard list of directories for the library, which is actually a file named liblibrary.a. The linker then uses this file as if it had been specified
precisely by name.

The directories searched include several standard system directories plus any that you specify with -L.

Normally the files found this way are library files---archive files whose members are object files. The linker handles an archive file by scanning through it for members which
define symbols that have so far been referenced but not defined. But if the file that is found is an ordinary object file, it is linked in the usual fashion. The only difference
between using an -l option and specifying a file name is that -l surrounds library with lib and .a and searches several directories.


-L 只是加入搜索库的路径,-l指定要链接的库
-ldl, dl就是库的名字
seupengdi
2013-04-27 23:55:12 +08:00
就是libdl.so吧 某种有用的动态库

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/67189

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX