Linux C++:链接器找不到 -lcrypto,但库在路径中
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 
原文地址: http://stackoverflow.com/questions/19406024/
Warning: these are provided under cc-by-sa 4.0 license.  You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
C++: linker cannot find -lcrypto, but the library is in the path
提问by Andry
I am compiling a C++ application using GNU g++. The project takes advantage of  OpenSSL libraries.
我正在使用 GNU 编译 C++ 应用程序g++。该项目利用了 OpenSSL 库。
Background
背景
On my machine (a 64 bit CentOS quad core) I compile and link my files.
在我的机器(64 位 CentOS 四核)上,我编译并链接我的文件。
g++ -g -c -L/usr/local/lib/ -L/usr/lib64/ 
    -I/usr/local/include/ -I/usr/local/ssl/include/ 
    -lcrypto mysrc1.cpp mysrc2.cpp mysrc3.cpp
g++ -L/usr/local/lib/ -L/usr/lib64/ -lcrypto 
    *.o -o ./myapp.out
My application uses function MD5which is contained in libcrypto.so. As you can see I specify to g++the dirs where to search using the -L, -Ioptions and which libraries to look for with the -l<lib-name>option. There are some trivial paths like /usr/local/libwhich can be omitted of course, but I specified them because the makefile is parametric. 
我的应用程序使用MD5包含在libcrypto.so. 如您所见,我指定g++目录使用-L,-I选项搜索的位置以及使用该选项查找的库-l<lib-name>。有一些简单的路径/usr/local/lib,当然可以省略,但我指定了它们,因为 makefile 是参数化的。
The problem
问题
My problem is that I can successfully compile my stuff (first command), but linking fails(second command):
我的问题是我可以成功编译我的东西(第一个命令),但链接失败(第二个命令):
/usr/bin/ld: cannot find -lcrypto
collect2: ld returned 1 exit status
make: *[cppsims_par] Error 1
/usr/bin/ld: 找不到 -lcrypto
collect2: ld 返回 1 个退出状态
制作:*[cppsims_par] 错误 1
But I did check folders and everything... libcrypto.sois inside /usr/lib64/. What is going on?
但我确实检查了文件夹,所有东西......libcrypto.so都在里面/usr/lib64/。到底是怎么回事?
回答by tristan
It may help if you try strace to find why it failed the file lookup
如果您尝试 strace 找出文件查找失败的原因,这可能会有所帮助
strace -f -e trace=file g++ -L/usr/local/lib/ -L/usr/lib64/ -lcrypto 
    *.o -o ./myapp.out
回答by Andry
I did find the problem and it is related to this question: ld cannot find an existing library
我确实找到了问题,它与这个问题有关:ld 找不到现有的库
Actually I had no symlink libcrypto.soand the compiler was not able to find the library...
实际上我没有符号链接libcrypto.so并且编译器无法找到库...

