(I saw answers of every single StOF questions regarding this - none fully helped. I'm very frustrated after trying so hard for 3 days & nights.)
Case 1 - as if curl isn't statically linked
x86_64-w64-mingw32-gcc-10.2.0.exe -o main.exe main.c "C:\curl-7.77.0-win64-mingw\lib\libcurl.a" -DCURL_STATICLIB
Throws unending lines of error, as if libcurl isn't statically linked with its dependencies*:
...\lib\libcurl.a(http2.o):(.text+0x7f): undefined reference to `nghttp2_version'
...\lib\libcurl.a(http2.o):(.text+0x297): undefined reference to `nghttp2_submit_rst_stream'
... (then the errors include many more undefined reference to symbols from nghttp2, ssl, crypt, ssh, gsasl)
It is so enormously saddening to see how many people have struggled and are still struggling to statically link libcurl
to their program. So much so that a very active Curl maintainer said: "building static is a roller coaster left for the users to deal with on their own as its such a never-ending race for us to try to support."
Since linker
is saying undefined references, then libcurl.a
must be:
Linker
is sensitive to sequence. Example: If libbrotlidec-static.a
needs a function/symbol which is inside libbrotlienc-static.a
, then libbrotlienc-static.a
must be mentioned before libbrotlidec-static.a
A static library is an archive
.a
of object.obj
files. And they're not statically linked in themselves. That's why, to linksome-static-library.a
to a program, you need to collect and manually mentionevery.a
single.a
static.a
library.a
that are dependencies ofsome-static-library.a
.
In my Chat@Terminal:~$ project, I should have a make.bat
file which shows how to statically link libcurl
to a program using gcc
or mingw
. And finally static-compile the whole program, and ship without any runtime dependency!
On a side-note, curl's precompiled-binary website says: Curl_x.x.x is statically linked with: [list of libraries you provided]. Break your misconception that, the statement made at the website means: Curl.exe
is statically linked with the libs, not libcurl
.