小编典典

找不到libcrypto库错误

linux

当我尝试编译C它使用OpenSSL的代码“密码”的库函数与COMAND线-lcryptogcc 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`

这可能是什么原因?

找到命令结果

$ 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

有人可以帮忙吗,或者指出我正在做的任何错误

@ 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

非常感谢


阅读 923

收藏
2020-06-03

共1个答案

小编典典

-L /usr/local/ssl/lib/在之前,将其添加到GCC命令行中-lcrypto。由于您是根据下的OpenSSL标头构建的,因此/usr/local/ssl,您还需要链接到具有相同前缀的实际库(即使您似乎只在其中安装了静态库,这可能也可能不是您的意图;您可能需要正确地重新安装从源代码构建的OpenSSL)。

(编辑)要修复dlopen()链接器找不到的和朋友,请添加-ldl到GCC命令行中。-ldl告诉连接器还针对libdl.so链路,其是包含共享库dlopen()dlsym()dlclose()等;
这些功能由OpenSSL在内部使用,因此-ldl在使用-lcrypto(在Linux上)时是间接依赖项。因为要链接到libcrypto的静态版本,所以需要显式链接所有间接依赖项。

如果您不熟悉链接到正确的库的方法,建议您使用从操作系统软件包管理器安装的OpenSSL。可能会为您节省一些麻烦。

2020-06-03