Skip to content

libmariadbclient: fix missing zstd and curl in --libs_sys output#30113

Draft
thefallentree wants to merge 1 commit into
msys2:masterfrom
thefallentree:fix-libmariadb-remote-io-static-linking
Draft

libmariadbclient: fix missing zstd and curl in --libs_sys output#30113
thefallentree wants to merge 1 commit into
msys2:masterfrom
thefallentree:fix-libmariadb-remote-io-static-linking

Conversation

@thefallentree

@thefallentree thefallentree commented Jun 21, 2026

Copy link
Copy Markdown

Problem

`CLIENT_PLUGIN_ZSTD=STATIC` and `CLIENT_PLUGIN_REMOTE_IO=STATIC` embed zstd
and curl code into `libmysqlclient_r.a`, but `mariadb_config --libs_sys` does
not report `-lzstd` or `-lcurl.dll`. This breaks static linking on Windows:
applications get undefined references to zstd symbols and `_imp_curl*` import
stubs at link time.

Repro (MINGW64/UCRT64, any project linking the static client lib):

```
libmysqlclient_r.a(compress_zstd.c.obj): undefined reference to `ZSTD_compress'
libmysqlclient_r.a(remote_io.c.obj): undefined reference to `__imp_curl_multi_init'
... (~25 more)
```

Root Cause

Both `ZSTD_LIBRARY` and `CURL_LIBRARIES` are appended to `SYSTEM_LIBS` inside
`libmariadb/CMakeLists.txt` without `PARENT_SCOPE`. The sibling
`mariadb_config/` subdirectory (processed after `libmariadb/`) reads the
top-level `SYSTEM_LIBS` to build the `@extra_dynamic_LDFLAGS@` substitution
that becomes `#define LIBS_SYS` in `mariadb_config.c`. It never sees those
additions, so `--libs_sys` only outputs the Win32 baseline
(`-lws2_32 -ladvapi32 ...`) and omits `-lzstd` and `-lcurl.dll`.

Fix

After `cmake` configure (which generates `mariadb_config.c`), patch that file
to append `-lzstd -lcurl.dll` to the `LIBS_SYS` string literal before it is
compiled into `mariadb_config.exe`.

`-lcurl.dll` (not `-lcurl`) is used deliberately: on MinGW the linker resolves
`-lcurl.dll` to `libcurl.dll.a` (the import library that provides the
`_imp_curl` stubs needed by the statically-embedded `remote_io` plugin),
whereas `-lcurl` may resolve to `libcurl.a` (the static archive, which does
not define `_imp_curl
`).

@thefallentree thefallentree marked this pull request as draft June 21, 2026 23:58
@thefallentree thefallentree force-pushed the fix-libmariadb-remote-io-static-linking branch from 6538593 to f731149 Compare June 22, 2026 00:18
@thefallentree thefallentree changed the title libmariadbclient: change REMOTE_IO plugin to DYNAMIC to fix static linking libmariadbclient: fix missing zstd and curl in --libs_sys output Jun 22, 2026
CLIENT_PLUGIN_ZSTD=STATIC and CLIENT_PLUGIN_REMOTE_IO=STATIC embed zstd
and curl code into libmysqlclient_r.a, but mariadb_config --libs_sys does
not report -lzstd or -lcurl.dll. This breaks static linking on Windows:
applications get undefined references to zstd symbols and __imp_curl_*
import stubs at link time.

Root cause: both ZSTD_LIBRARY and CURL_LIBRARIES are added to SYSTEM_LIBS
inside libmariadb/CMakeLists.txt without PARENT_SCOPE, so the sibling
mariadb_config/ subdirectory never sees them when generating --libs_sys.

Fix: patch the generated mariadb_config.c before compilation to append
-lzstd and -lcurl.dll to LIBS_SYS. Using -lcurl.dll (not -lcurl) ensures
the MinGW linker selects libcurl.dll.a (the import library with __imp_*
stubs) rather than libcurl.a.
@thefallentree thefallentree force-pushed the fix-libmariadb-remote-io-static-linking branch from f731149 to 753eb9c Compare June 22, 2026 00:20
@dragon-archer

Copy link
Copy Markdown
Collaborator

Usually a patch is better than a sed for this.

@thefallentree

Copy link
Copy Markdown
Author

Usually a patch is better than a sed for this.

yeah this is unfortunately a bug in the upstream release, I am working on a patch instead

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants