Linux C ++ linker / usr / bin / ld

I wrote a small application on Redhat Linux 6 using g ++ 4.4.6. After compiling, I got the error

/usr/bin/ld: cannot find -lcrypto


I did a search for the crypto library and found them here.

[root@STL-DUNKEL01 bin]# find / -name libcrypto*


My question is, is the compilation error in / usr / bin / ld caused by the absence of / usr / lib64 / in the search path? If so, how can I add it?



source to share

4 answers

You can provide directories to search for libraries as a parameter gcc

, for example -L<directory_to_search_in>

. Note that there -L

can be multiple parameters for. Also, are you trying to build a 32-bit or 64-bit application?



No, you probably misstated the reason.

You need

to link. This is usually a symbolic link to one of the real libraries, whose name (

) will be embedded in the binary. At runtime, only this library is required, but a symbolic link is required for compilation.

See Diego E. Pettenò: Linkers and Names for details .



You must add -L/usr/lib64

when calling gcc or ld.

Note that you can also specify LD_LIBRARY_PATH, but this is considered malicious for this. (The link mentions Solaris specifically, but the problems apply to other OSs as well.)


  • LD_LIBRARY_PATH is used as the preference for any system linker link time or default. If (God forbid) you installed something like / dcs / spod / baduser / lib, if there was a cracked version of libc in that directory (for example), your account could be compromised. It is for this reason that set-uid programs ignore LD_LIBRARY_PATH entirely.
  • When the code is compiled and depends on it, it can cause confusion when different libraries are installed in different directories, for example there is libtiff in / usr / openwin / lib and / usr / local / lib.In this case, the old library is the older one used some of the programs that ship with Solaris.
  • Sometimes, when using precompiled binaries, they can be built with third-party libraries in specific locations; ideally the code should either come with the libraries, or install it in a specific location, or bundle the code as a pre-install step. Solaris 7 introduces $ ORIGIN, which allows you to specify the relative location of the library at runtime (see the Solaris Linkers and Libraries Guide). An alternative is to set LD_LIBRARY_PATH for each program, either as a wrapper for a real program or as a shell alias. Note, however, that LD_LIBRARY_PATH can be inherited by programs called by the wrapped ...


Add directory to /etc/

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



All Articles