[MinGW-Users] Need advice on how to include OpenSSL statically in linux/windows crossbuild DLL

Back to archive index
Eli Zaretskii eliz****@gnu*****
Thu Jan 7 00:04:19 JST 2021


> Date: Tue, 05 Jan 2021 23:20:17 +0100
> From: Benedikt Hallinger <beni****@halli*****>
> 
> in my project fgcom-mumble (https://github.com/hbeni/fgcom-mumble) i 
> build a windows DLL from linux.
> This all wents good so far and the DLL looks good when i do not include 
> SSL.
> 
> When i do, the compilation succeeds, but two DLL entries are reported 
> missing from the final generated DLL, and i really struggle to find out 
> why.
> The missing bits are OpenSSLs libcrypto and libssl, against which i link 
> statically (i try to at least).
> I have seen this with https://github.com/lucasg/Dependencies tool.
> 
> The makefile generates this command:
> x86_64-w64-mingw32-g++-posix -fPIC --shared -DMINGW_WIN64 -o 
> fgcom-mumble.dll lib/io_plugin.cpp lib/radio_model.cpp lib/audio.cpp 
> lib/io_UDPServer.cpp lib/io_UDPClient.cpp lib/garbage_collector.cpp 
> fgcom-mumble.cpp -L./lib/openssl/ -static -lssl.dll -lcrypto.dll 
> -DSSLFLAGS -lws2_32 -lcrypt32 -static-libgcc -static-libstdc++ -I. 
> -I./lib -g3 -DDEBUG -I./lib/openssl/include/ -Wl,-Bstatic -lstdc++ 
> -lpthread -lws2_32

First, I think you are in the wrong forum, because the above indicates
you are using MinGW64 tools, not MinGW tools from mingw.org.  This
mailing list is for the latter.

> ./lib/openssl/libcrypto.dll.a and ./lib/openssl/libssl.dll.a are there 
> and resolved (if i rename them, the build fails).

The Dependencies display indicates that the program expects to find
libcrypto-1_1-x64.dll and libssl-1_1-x64.dll.  My guess is that the
link-time switches you used, -lssl.dll and -lcrypto.dll, caused the
linker to find libssl.dll.a and libcrypto.dll.a, which are import
libraries, so linking against them made your program dependent on the
above 2 DLLs, which is not what you wanted.

To link statically against these libraries, you need to make sure you
have libssl.a and libcrypto.a, which are static libraries, and link
with -lssl and -lcrypto switches instead.  If you don't have libssl.a
and libcrypto.a, then your system doesn't have the static libraries,
and you cannot link program statically against them.

> My impression was that the "static" switch should have included the dlls 
> into my archive.

It didn't, and it cannot: DLLs cannot be statically linked, AFAIK.
What you did was statically link against the _import_ libraries, which
make your program depend on the DLLs at run time.



More information about the MinGW-Users mailing list
Back to archive index