Weird things with libCurl and OpenSSL

2019-03-04 19:32发布

问题:

It's me again. I just can't understand, why it goes that way!

I downloaded compiled static libs of OpenSSL, from here, this link is on the official cUrl site in Download page. I downloaded Zlib and compiled them, then I compiled libcurl with

mingw32-make mingw32-ssl-zlib

I changed in all makefile.m32 pathes to the Zlib and OpenSSL files. All went fine, I recieved libcurl.a and libcurldll.a. I added into lib folder of my project libcurl.a and libeay32.a, libssleay32.a and libz.a. I built project - it says that everything is fine. I run - and it just terminated. I'm using MinGW and Eclipse.

It is compiled with this:

g++ -DCURL_STATICLIB -O0 -g3 -Wall -c -fmessage-length=0 -osrc\main.o ..\src\main.cpp

g++ -L..\lib -oYTUploader.exe src\main.o -lcurl -lws2_32 -lwldap32 -leay32 -lssleay32 -lz

I run DependencyWalker, and it says that it's missing ieshims.dll, libeay32.dll and ssleay32.dll. But WHY? Why it want OpenSSL dll, I'm using static linking! I built static libCurl library, with static libs of OpenSSL. About ieshims.dll I also can't get why it needs it! Help, please, I have no idea what is wrong! I compiled cUrl according to the instruction, everything should be fine..

回答1:

The openssl-libs you link against seem to be import-libraries. That means they only contain the information your code needs to call functions and then load and call the corresponding functions from the dll.

So the problem is: although you link to static libs, the libs then load and use dynamic dlls. They are no "real" static libs.

One solution is getting other libs (or compile them yourself), or even easier: you just copy the dlls into the directory where your .exe resides and you should be fine.



回答2:

Use the configure script to tell ld where openssl has installed the files. the defaults are as follows:

tar -zxf curl-7.33.0.tar.gz
cd curl-7.33.0
./configure --prefix=/opt/curlssl --with-ssl=/usr/local/ssl --enable-http --enable-ftp LDFLAGS=-L/usr/local/ssl/lib CPPFLAGS=-I/usr/local/ssl/include

make
make install