找不到 libcrypto 库错误 [英] Cannot find libcrypto library error
问题描述
当我试图编译一个 C
代码,它使用 openssl 'crypto' 库函数和命令行 -lcrypto
和 gcc 4.4.3
它给出了一个错误
When i am trying to compile a C
code which uses openssl 'crypto' library functions with comand line -lcrypto
with gcc 4.4.3
it gives an error
`@ubu:$ gcc -ggdb aes_m.c -Werror -Wall -I /usr/local/ssl/include/ -lcrypto -o aes
/usr/bin/ld: cannot find -lcrypto
collect2: ld returned 1 exit status`
这可能是什么原因??
我已经完成了这个讨论 ld 找不到现有的图书馆但这无济于事.
I have already gone through this discussion ld cannot find an existing library but that does not help.
定位命令结果
$ locate libcrypto
/home/abhi/Downloads/openssl-1.0.1b/libcrypto.a
/home/abhi/Downloads/openssl-1.0.1b/libcrypto.pc
/lib/libcrypto.so.0.9.8
/lib/i486/libcrypto.so.0.9.8
/lib/i586/libcrypto.so.0.9.8
/lib/i686/cmov/libcrypto.so.0.9.8
/usr/lib/libcrypto.so.0.9.8
/usr/lib/vmware-tools/lib32/libcrypto.so.0.9.8
/usr/lib/vmware-tools/lib32/libcrypto.so.0.9.8/libcrypto.so.0.9.8
/usr/lib/vmware-tools/lib64/libcrypto.so.0.9.8
/usr/lib/vmware-tools/lib64/libcrypto.so.0.9.8/libcrypto.so.0.9.8
/usr/local/ssl/lib/libcrypto.a
/usr/local/ssl/lib/pkgconfig/libcrypto.pc
有人可以帮忙解决这个问题或指出我做的任何错误
Can someone please help on this or point out any mistake i am doing
@ Daniel Roethlisberger 尝试使用 -L 标志,但导致这些错误
@ Daniel Roethlisberger tried using the -L flag but that resulted in these errors
gcc -ggdb aes_m.c -Werror -Wall -I /usr/local/ssl/include/ -L /usr/local/ssl/lib -lcrypto -o aes
/usr/local/ssl/lib/libcrypto.a(dso_dlfcn.o): In function `dlfcn_globallookup':
dso_dlfcn.c:(.text+0x2d): undefined reference to `dlopen'
dso_dlfcn.c:(.text+0x43): undefined reference to `dlsym'
dso_dlfcn.c:(.text+0x4d): undefined reference to `dlclose'
/usr/local/ssl/lib/libcrypto.a(dso_dlfcn.o): In function `dlfcn_pathbyaddr':
dso_dlfcn.c:(.text+0x8f): undefined reference to `dladdr'
dso_dlfcn.c:(.text+0xe9): undefined reference to `dlerror'
/usr/local/ssl/lib/libcrypto.a(dso_dlfcn.o): In function `dlfcn_bind_func':
dso_dlfcn.c:(.text+0x4b1): undefined reference to `dlsym'
dso_dlfcn.c:(.text+0x590): undefined reference to `dlerror'
/usr/local/ssl/lib/libcrypto.a(dso_dlfcn.o): In function `dlfcn_bind_var':
dso_dlfcn.c:(.text+0x611): undefined reference to `dlsym'
dso_dlfcn.c:(.text+0x6f0): undefined reference to `dlerror'
/usr/local/ssl/lib/libcrypto.a(dso_dlfcn.o): In function `dlfcn_unload':
dso_dlfcn.c:(.text+0x755): undefined reference to `dlclose'
/usr/local/ssl/lib/libcrypto.a(dso_dlfcn.o): In function `dlfcn_load':
dso_dlfcn.c:(.text+0x837): undefined reference to `dlopen'
dso_dlfcn.c:(.text+0x8ae): undefined reference to `dlclose'
dso_dlfcn.c:(.text+0x8f5): undefined reference to `dlerror'
collect2: ld returned 1 exit status
非常感谢
推荐答案
将 -L/usr/local/ssl/lib/
添加到 GCC 命令行中,在 -lcrypto<之前/代码>.由于您是针对
/usr/local/ssl
下的 OpenSSL 标头构建的,因此您还需要链接到相同前缀下的实际库(即使您似乎只在那里安装了静态库,这可能是也可能不是您的意图;您可能需要正确地重新安装从源代码构建的 OpenSSL).
Add -L /usr/local/ssl/lib/
into the GCC command line, before the -lcrypto
. Since you are building against the OpenSSL headers under /usr/local/ssl
, you also need to link against the actual library under the same prefix (even though you only appear to have a static one installed there, that may or may not be your intention; you may need to properly reinstall your OpenSSL built from source).
(edit) 要修复链接器找不到 dlopen()
和朋友的问题,请将 -ldl
添加到 GCC 命令行中.-ldl
告诉链接器也链接到 libdl.so,这是包含 dlopen()
, dlsym()
, 的共享库>dlclose()
等;这些函数由 OpenSSL 在内部使用,因此,当使用 -lcrypto
(在 Linux 上)时,-ldl
是一个间接依赖项.因为您要链接到 libcrypto 的静态版本,所以您需要显式链接所有间接依赖项.
(edit) To fix the dlopen()
and friends not being found by the linker, add -ldl
into the GCC command line. -ldl
tells the linker to also link against libdl.so, which is the shared library containing dlopen()
, dlsym()
, dlclose()
etc.; these functions are used by OpenSSL internally and thus, -ldl
is an indirect dependency when using -lcrypto
(on Linux). Because you are linking to a static version of libcrypto, you need to explicitly link against all indirect dependencies.
如果您不熟悉链接到正确的库,我建议您使用从操作系统包管理器安装的 OpenSSL;它可能会为您省去一些麻烦.
If you are not familiar with linking to the proper libraries, I'd suggest you use OpenSSL as installed from your Operating System package manager; it might save you some trouble.
这篇关于找不到 libcrypto 库错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!