-
-
Notifications
You must be signed in to change notification settings - Fork 98
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
MinGW Build Regression #233
Comments
Thanks for the report. Need to fix it properly. @seanm @MaartenBent FYI |
Looks good to me, it works fine on Ubuntu. I also don't have OpenBSD to check. One small remark, you could move the |
I've setup a MinGW build CI that confirms the regression: https://github.com/tbeu/matio/actions/runs/7822032818/job/21340240188 |
Issue <tbeu#187> indicates that OpenBSD requires an explicit specification of -lc on the linker line when -Wl,--no-undefined is used. Unfortunately, unconditionally adding -lc is not possible, as that breaks MinGW builds. This commit adds a proper CMake test to check whether -lc is required when using -Wl,--no-undefined. If and only if it is required, -lc will be added to the linker flags. This now fixes <tbeu#233>.
Issue <tbeu#187> indicates that OpenBSD requires an explicit specification of -lc on the linker line when -Wl,--no-undefined is used. Unfortunately, unconditionally adding -lc is not possible, as that breaks MinGW builds. This commit adds a proper CMake test to check whether -lc is required when using -Wl,--no-undefined. If and only if it is required, -lc will be added to the linker flags. This now fixes <tbeu#233>.
I've now attempted to write a proper generic test that doesn't depend on the OS but doesn't also add Since I don't have an OpenBSD system, I can't test that case, but I did take care when writing the CMake test. If something comes up on OpenBSD, this should hopefully be easily fixable. |
Issue tbeu#187 appears to indicate that OpenBSD requires an explicit specification of -lc on the linker line if -Wl,--no-undefined is used. Unfortunately, -lc is not available on MinGW (due to the C runtime working different on Windows), so adding it whenever -lm is also linked against does not work. This commit reworks the entire CMake linker flag logic: - Remove dependency on CMake >= 3.17.0 for some checks -- we need to do a manual check_c_source_compiles() anyway (due to check_linker_flag() not triggering the potential error when -lc is not supplied), so we can drop that dependency. - Check for -Wl,--no-undefined both without and with an explicit -lc on the command line. If either version works, assume we can pass GNU-style linker options. If only the explicit version works, also pass -lc explicitly. (If both work don't, because even if -lc works, such as on a standard Linux, one would typically not pass it explicitly while compiling software.) Fixes tbeu#233
Issue tbeu#187 appears to indicate that OpenBSD requires an explicit specification of -lc on the linker line if -Wl,--no-undefined is used. Unfortunately, -lc is not available on MinGW (due to the C runtime working different on Windows), so adding it whenever -lm is also linked against does not work. This commit reworks the entire CMake linker flag logic: - Remove dependency on CMake >= 3.17.0 for some checks -- we need to do a manual check_c_source_compiles() anyway (due to check_linker_flag() not triggering the potential error when -lc is not supplied), so we can drop that dependency. - Check for -Wl,--no-undefined both without and with an explicit -lc on the command line. If either version works, assume we can pass GNU-style linker options. If only the explicit version works, also pass -lc explicitly. (If both work don't, because even if -lc works, such as on a standard Linux, one would typically not pass it explicitly while compiling software.) Fixes tbeu#233
Issue #187 appears to indicate that OpenBSD requires an explicit specification of -lc on the linker line if -Wl,--no-undefined is used. Unfortunately, -lc is not available on MinGW (due to the C runtime working different on Windows), so adding it whenever -lm is also linked against does not work. This commit reworks the entire CMake linker flag logic: - Remove dependency on CMake >= 3.17.0 for some checks -- we need to do a manual check_c_source_compiles() anyway (due to check_linker_flag() not triggering the potential error when -lc is not supplied), so we can drop that dependency. - Check for -Wl,--no-undefined both without and with an explicit -lc on the command line. If either version works, assume we can pass GNU-style linker options. If only the explicit version works, also pass -lc explicitly. (If both work don't, because even if -lc works, such as on a standard Linux, one would typically not pass it explicitly while compiling software.) Fixes #233
The fix for #187 caused a build regression in MinGW for me (amd64, CMake Buildsystem):
-lm
for the math functions, and automatically maps them to the correct CRT. But it does not provide a-lc
, because normally nobody explicitly specifies that.-lc
to the compiler line due to the commit f058e5d.This causes MinGW builds to fail, since
HAVE_LIBM
is true on those systems, but-lc
doesn't work there.The least wrong simple fix I could come up with (without testing on OpenBSD, which I don't use) was to simply also check for
-lc
and then only link to that if it's available. The following patch works for me on Linux, macOS and Windows:While this will solve the issue, the most appropriate fix would probably be to only do that if OpenBSD requires this, for example performing a
--no-undefined
link check, and only add-lc
if that is required to avoid the linker error with that flag. However, I can also open a pull request for my workaround if that's more the route you'd want to go in.The text was updated successfully, but these errors were encountered: