简体   繁体   English

找不到 libcrypto 库错误

[英]Cannot find libcrypto library error

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当我尝试编译使用 openssl 'crypto' 库函数和命令行-lcryptogcc 4.4.3C代码时,它给出了一个错误

`@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 library but 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非常感谢

Add -L /usr/local/ssl/lib/ into the GCC command line, before the -lcrypto .-lcrypto之前,将-L /usr/local/ssl/lib/到 GCC 命令行中。 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).由于您正在针对/usr/local/ssl下的 OpenSSL 标头进行构建,因此您还需要链接到相同前缀下的实际库(即使您似乎只在那里安装了一个静态库,这可能是也可能不是您的)意图;您可能需要正确重新安装从源代码构建的 OpenSSL)。

(edit) To fix the dlopen() and friends not being found by the linker, add -ldl into the GCC command line. (编辑)要修复链接器找不到的dlopen()和朋友,请将-ldl添加到 GCC 命令行中。 -ldl tells the linker to also link against libdl.so, which is the shared library containing dlopen() , dlsym() , dlclose() etc.; -ldl告诉链接器也链接 libdl.so,这是包含dlopen()dlsym()dlclose()等的共享库; these functions are used by OpenSSL internally and thus, -ldl is an indirect dependency when using -lcrypto (on Linux).这些函数由 OpenSSL 在内部使用,因此,在使用-lcrypto (在 Linux 上)时, -ldl是一个间接依赖项。 Because you are linking to a static version of libcrypto, you need to explicitly link against all indirect dependencies.因为您要链接到 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;如果您不熟悉链接到正确的库,我建议您使用从操作系统包管理器安装的 OpenSSL; it might save you some trouble.它可能会为您节省一些麻烦。

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

This will create the required shared library libcrypto.so .这将创建所需的共享库libcrypto.so You'll find more in the INSTALL file.您将在 INSTALL 文件中找到更多信息。

Also, if you run into this error during 'make'此外,如果您在“制作”期间遇到此错误

"....can not be used when making a shared object

recompile with -fPIC用 -fPIC 重新编译

./config shared -fPIC

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

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