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*
/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, 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?
Thank.
source to share
No, you probably misstated the reason.
You need libcrypto.so
to link. This is usually a symbolic link to one of the real libraries, whose name ( libcrypto.so.??
) 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 .
source to share
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.)
Quote:
- 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 ...
source to share