繁体   English   中英

使用 MinGW 在 Windows 上使用 OpenSSL “找不到 -lcrypto -lssl”

[英]"cannot find -lcrypto -lssl" with OpenSSL on Windows with MinGW

尝试 openssl 的 ac 代码,在命令提示符下编译时出现此错误。

c:\openssl>gcc -lssl -lcrypto -o test test.c -IC:\openssl\include\
c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/bin/ld.exe: cannot find -lssl
c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/bin/ld.exe: cannot find -lcrypto
collect2.exe: error: ld returned 1 exit status

现在我该怎么办,请帮忙。

编辑:即使这些也无济于事:

c:\openssl>gcc -o test test.c  -lssl -lcrypto -Ic:\openssl\include\
c:\openssl>gcc -o test test.c -I c:\openssl\include\ -L c:\openssl\lib -lssl -lcrypto
c:\openssl>gcc -o test test.c -Lc:\openssl\lib -lssl -lcrypto -Ic:\openssl\include\

首先,您需要用 mingw 编译 openssl,您链接到的二进制文件是用 Visual Studio 编译的,已经过时并且包含安全漏洞。

0.9.8 支持已停止,因此我建议使用 1.0.1+。

安装 ActivePerl 并删除 Stawberry Perl,因为它与 openssl 不兼容。

从以下网址下载最新的 1.0.1 源代码 (openssl-1.0.1q.tar.gz): https ://openssl.org/source/

在您将 openssl 源提取到的目录中的 msys 控制台中运行以下命令:

 $ perl Configure mingw --prefix=/c/openssl
 $ make depend
 $ make
 $ make install

然后运行你的编译命令:

gcc -o test test.c -Lc:\openssl\lib -lssl -lcrypto -Ic:\openssl\include\

编辑:mingw 在 0.9.8 上存在构建问题,因此请使用 1.0.1 或更高版本并使用 ActivePerl 而不是 Strawberry Perl。

例如,我的做法有所不同。
我从https://www.openssl.org/community/binaries.html下载了编译后的二进制文件。
然后就链接到他们。 使用 -L 将搜索目录添加到链接器( 在此处解释)。

最后我得到了

g++ my_program.cpp -I"C:\Program Files (x86)\OpenSSL-Win32\include" -L"C:\Program Files (x86)\OpenSSL-Win32\lib\MinGW" -lssl -lcrypto

您似乎在C:/openssl/中拥有它,因此(并且冒着陈述显而易见的风险)对您的环境进行必要的更改。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM