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`
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.
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
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
You need to install the development code (package) for the crypto library. Specifically, you need /usr/lib/libcrypto.so (no numerical suffix) pointing at (symlinked to) /usr/lib/libcrypto. so.
The OpenSSL crypto library ( libcrypto ) implements a wide range of cryptographic algorithms used in various Internet standards. The services provided by this library are used by the OpenSSL implementations of TLS and CMS, and they have also been used to implement many other third party products and protocols.
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) 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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With