Repository navigation
Conversation
Finding regex.h was taken to mean that regcomp() etc. are available. On some systems the header belongs to a separate library that is not linked by default: on MSYS2 (MinGW-w64) regex.h comes from libsystre (TRE), whose regex.h defines regcomp etc. as macros for tre_regcomp etc., so GKlib compiles but fails to link (undefined tre_regcomp). Now compile and link a small program that calls regcomp(), regexec(), regerror() and regfree(). If that fails with the C library alone, try systre, tre, gnurx and regex, and add the first that works to GKlib's public link interface (as for libexecinfo). If none works, fall back to GKlib's own implementation (gkregex) instead of building a library that cannot be linked. check_symbol_exists() is not used, because it accepts a macro and so cannot detect the TRE case. The GKREGEX option (make config gkregex=set) was declared but had no effect; it now selects gkregex unconditionally. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01HhHuoyV4eedKKTaFRt9Wfi
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
CMakeLists.txttakes findingregex.hto mean thatregcomp()and friends can be linked. That is true where they are in libc (glibc, macOS, the BSDs), but not whereregex.hbelongs to a separate library. On MSYS2 (MinGW-w64, e.g. UCRT64)regex.hcomes from libsystre (built on TRE). GKlib builds, but anything linked with it fails:Fix
regcomp(),regexec(),regerror()andregfree().systre,tre,gnurxandregexin turn. Add the first one that works to GKlib'sPUBLIClink libraries, so it is exported tofind_package(GKlib)users. This is the same approach already used forlibexecinfo.gkregex) rather than producing a library that cannot be linked.check_symbol_exists()is deliberately not used: it accepts a macro, and TRE'sregex.hdefinesregcompetc. as macros fortre_regcompetc., so it would wrongly report success.GKREGEXoption (make config gkregex=set) was declared but had no effect. It now selectsgkregexunconditionally, which gives users a way to avoid the system regex.Testing
MSYS2 UCRT64, GCC 16.2.0, CMake 4.4.4, libsystre 1.0.2. Each case builds and installs GKlib (
GKLIB_BUILD_APPS=OFFunless stated), then builds a smallfind_package(GKlib)program that callsgk_strstr_replace()and runs it:systredetected and exported; program runs correctlyGKLIB_BUILD_APPS=ONCMAKE_C_STANDARD=17gkregex; program runs correctlygkregex.cfails to compile, as fixed by #66; with #66 applied, program runs correctlyGKREGEX=ON,CMAKE_C_STANDARD=17gkregex; program runs correctlymacOS (Apple clang). The library check passes against libc, nothing extra is linked and the program runs correctly. I also ran
GKREGEX=ON, plus a TRE-styleregex.hthat mapsregcomptotre_regcomp. With no library providingtre_regcomp, GKlib falls back togkregex. When alibtreis available,treis detected, exported and linked. In both cases the test program runs correctly. Without this change, that setup fails to link (_tre_regcompundefined).Not tested: Linux (the libc check should pass exactly as on macOS) and native MSVC (no
regex.h, so behaviour is unchanged).Known limitation: a fully static link (
-static) on MSYS2 still needs-ltre -lintl -liconvadded by the user.libsystre.adepends on these, and the check only sees the shared import library. SettingGKREGEX=ONavoids this.Reported by Claude Code on behalf of @pjknowles, following a request from @ajmay81.
🤖 Generated with Claude Code
https://claude.ai/code/session_01HhHuoyV4eedKKTaFRt9Wfi