libmariadbclient: fix missing zstd and curl in --libs_sys output#30113
Draft
thefallentree wants to merge 1 commit into
Draft
libmariadbclient: fix missing zstd and curl in --libs_sys output#30113thefallentree wants to merge 1 commit into
thefallentree wants to merge 1 commit into
Conversation
6538593 to
f731149
Compare
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.
f731149 to
753eb9c
Compare
Collaborator
|
Usually a patch is better than a |
Author
yeah this is unfortunately a bug in the upstream release, I am working on a patch instead |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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`).