Linux 找不到 libcrypto 库错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10368671/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Cannot find libcrypto library error
提问by abhi
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
当我尝试编译C
使用 openssl 'crypto' 库函数和命令行的代码-lcrypto
时gcc 4.4.3
,会出现错误
`@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`
what can be the reason for this??
这可能是什么原因?
I have already gone through this discussion ld cannot find an existing librarybut that does not help.
我已经完成了这个讨论ld cannot find an existing library但这无济于事。
locate command results in
定位命令结果
$ 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 tried using the -L flag but that resulted in these errors
@ Daniel Roethlisberger 尝试使用 -L 标志,但这导致了这些错误
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
Many thanks
非常感谢
采纳答案by Daniel Roethlisberger
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).
添加-L /usr/local/ssl/lib/
到 GCC 命令行,在-lcrypto
. 由于您是针对 下的 OpenSSL 标头构建的/usr/local/ssl
,因此您还需要链接到相同前缀下的实际库(即使您似乎只在那里安装了一个静态库,这可能是也可能不是您的意图;您可能需要正确重新安装从源代码构建的 OpenSSL)。
(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.
(编辑)要修复dlopen()
链接器找不到的和朋友,请添加-ldl
到 GCC 命令行中。-ldl
告诉连接器还针对libdl.so链路,其是包含共享库dlopen()
,dlsym()
,dlclose()
等; 这些函数由 OpenSSL 在内部使用,因此-ldl
在使用-lcrypto
(在 Linux 上)时是间接依赖项。因为您要链接到 libcrypto 的静态版本,所以需要显式链接所有间接依赖项。
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.
如果您不熟悉链接到正确的库,我建议您使用从操作系统包管理器安装的 OpenSSL;它可能会为您节省一些麻烦。
回答by Daniel Hollas
This might be relevant for people who tried to build their own openssl from source and then use it to compile other programs (in my case Git)
这可能与那些试图从源代码构建自己的 openssl 然后使用它来编译其他程序的人有关(在我的情况下是 Git)
During configuration of openssl, add 'shared' option:
在配置 openssl 时,添加 'shared' 选项:
./config shared
./config shared
This will create the required shared library libcrypto.so
. You'll find more in the INSTALL file.
这将创建所需的共享库libcrypto.so
。您将在 INSTALL 文件中找到更多信息。
Also, if you run into this error during 'make'
此外,如果您在“制作”期间遇到此错误
"....can not be used when making a shared object
"....can not be used when making a shared object
recompile with -fPIC
用 -fPIC 重新编译
./config shared -fPIC
./config shared -fPIC