3

I wrote a small application on Redhat Linux 6 using g++ 4.4.6. After compilation, I received an error

/usr/bin/ld: cannot find -lcrypto

I did a search for the crypto library and find them here,

[root@STL-DUNKEL01 bin]# find / -name libcrypto*
/usr/lib64/libcrypto.so.0.9.8e
/usr/lib64/libcrypto.so.10
/usr/lib64/libcrypto.so.6
/usr/lib64/libcrypto.so.1.0.0

My question is whether the compilation error is caused by /usr/bin/ld not having /usr/lib64/ in the search path? If yes, how can I add it?

Thanks.

2607
  • 4,037
  • 13
  • 49
  • 64
  • 1
    possible duplicate of [ld cannot find an existing library](http://stackoverflow.com/questions/335928/ld-cannot-find-an-existing-library) – ephemient Mar 26 '12 at 16:29

4 Answers4

5

No, you have likely incorrectly diagnosed the cause.

You need a libcrypto.so to link against. This is usually a symlink to one of the actual libraries, whose soname (libcrypto.so.??) will be embedded into the binary. Only that library is needed at runtime, but the symlink is necessary to compile.

See Diego E. Pettenò: Linkers and names for more details.

ephemient
  • 198,619
  • 38
  • 280
  • 391
4

You have to add -L/usr/lib64 when calling gcc or ld.

Note, you can specify LD_LIBRARY_PATH as well/instead, but it is considered harmful to do so. (The link mentions Solaris specifically, but the issues apply to other OSs as well.)

Quote:

  • LD_LIBRARY_PATH is used in preference to any run time or default system linker path. If (God forbid) you had it set to something like /dcs/spod/baduser/lib, if there was a hacked version of libc in that directory (for example) your account could be compromised. It is for this reason that set-uid programs completely ignore LD_LIBRARY_PATH.
  • When code is compiled and depends on this to work, it can cause confusion where different versions of a library are installed in different directories, for example there is a libtiff in /usr/openwin/lib and /usr/local/lib. In this case, the former library is an older one used by some programs that come with Solaris.
  • Sometimes when using precompiled binaries they may have been built with 3rd party libraries in specific locations; ideally code should either ship with the libraries and install into a certain location or link the code as a pre-installation step. Solaris 7 introduces $ORIGIN which allows for a relative library location to be specified at run time (see the Solaris Linker and Libraries Guide). The alternative is to set LD_LIBRARY_PATH on a per-program basis, either as a wrapper program to the real program or a shell alias. Note however, that LD_LIBRARY_PATH may be inherited by programs called by the wrapped one ...
Attila
  • 28,265
  • 3
  • 46
  • 55
2

Add the directory to /etc/ld.so.conf

then run "sudo ldconfig" to make the changes take effect.

Community
  • 1
  • 1
Karoly Horvath
  • 94,607
  • 11
  • 117
  • 176
0

You can provide the directories to search for the libraries in as a parameter to gcc like so -L<directory_to_search_in>. And note that there can be multiple parameters to -L. Also, are you trying to build a 32-bit application or a 64-bit one?

Gangadhar
  • 1,893
  • 9
  • 9