-
-
Notifications
You must be signed in to change notification settings - Fork 96
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
cmake: add a proper test to determine if explicit linking against -lc is required #238
Conversation
Note: the windows-mingw test in this PR fails because the test execution doesn't work correctly, probably a minor CI setup issue. (See https://github.com/tbeu/matio/actions/runs/7831127379/job/21366733842?pr=238) Compare this to a different PR where the MinGW build wasn't yet fixed, and it failed already at the build stage in the windows-mingw test. (See https://github.com/tbeu/matio/actions/runs/7827524982/job/21355503568?pr=237) |
@seanm Can you please cross-check in OpenBSD? Thanks! |
Yes, my bad. Can you fix it on the fly. $MATDUMP is just different. |
6911ba8
to
d78a523
Compare
There now is a OpenBSD CI available. Feel free to rebase. |
Oh, nice! I didn't think github had that. Where can I RTFM on that? |
What excatly? OpenBSD CI or rebase button? |
The former. Thanks for sharing. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. But I would prefer message(VERBOSE ...)
.
This status messages should not be relevant for end users.
CMake also has some macros to handle the CMAKE_REQUIRED_
variables, that you could use instead of manually resetting them: https://cmake.org/cmake/help/latest/module/CMakePushCheckState.html
dd46722
to
58e52d6
Compare
I've now updated this PR to include all of the previous feedback, including using The OpenBSD CI has now run successfully, and the CMake checks work as intended:
This means that |
a91ab85
to
9893d4c
Compare
f249429
to
8442fbc
Compare
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
58e52d6
to
d39f93f
Compare
Thanks for fixing! Very appreciated. |
I've just noticed that the merge breaks the linking of matdump.exe on my Cygwin setup. The relevant configure output is:
The link command is
which results in about thousands lines of error messages. The previous link command was
with I tried to setup a Cygwin CI yesterday but failed. |
So cygwin does need libc, even though the implicit check succeeds. It can't find |
Also are you linking with msvc hdf5 libraries? I've never used cygwin myself, but mixing gcc and msvc is usually not a good idea. |
I tried a lot - even forcing -lc, but it only works if the merge is reverted. Yes, I also wondered why it links with MSVC static HDF5 libs. |
Most of the messages for undefined symbols you posted come from linking against MSVC static HDF5 libs, which obviously don't use the same C runtime as Cygwin, which is why those fail. (What I don't get is why they succeed if you revert the patch? They shouldn't work at all.) My guess is that |
So interestingly, in the constellation you describe (HDF5 installed via the official binary installer) and building from within Cygwin, I get the following error already compiling in cygwin before the CMake change:
However, when I install the hdf5-devel Cygwin package, I have the following behavior:
Since my commit only touches the build system, but not the source files, could it be that the object files from your previous build were still seen as current (because when using |
OK, after reinstalling libhdf5-devel in CygWin, unsinstalling the MSVC static libs and setting Finally, we can leave this as is. Thanks again for fixing and investigating. |
This pull request hopefully contains the proper way to fix the
-lc
issue raised in #187, without breaking MinGW as in #233.This was tested on Linux and Windows/MinGW, but not on OpenBSD (I don't have a system running). However, since the check is operating-system agnostic, it should hopefully work there as well.