Fix standalone example build issues - #6598
Open
mattjala wants to merge 3 commits into
Open
Conversation
mattjala
requested review from
glennsong09,
hyoklee,
jhendersonHDF and
lrknox
as code owners
August 6, 2026 16:46
The standalone examples build forces CMAKE_CXX_STANDARD 98, but H5public.h includes <cinttypes>, which requires C++11. Any C++ translation unit that includes hdf5.h is therefore affected, not just users of the C++ API, and the HDF5 C++ library itself is built as C++11 (config/flags/HDFCompilerCXXFlags.cmake). The C++ examples do not compile as a result, against static or shared HDF5 alike. Only the standalone build is affected, which is why this is not visible in ordinary use. The C++98 setting lives in BASIC_SETTINGS, and HDF5Examples/CMakeLists.txt skips that whole block when EXAMPLES_EXTERNALLY_CONFIGURED is set -- which HDF5 does for its own in-tree example build (config/cmake/HDF5ExampleCache.cmake). Built in tree, the examples inherit HDF5's C++11 and compile normally, and that is the path the CI workflows exercise. The standalone path, where the C++98 setting does apply, is driven by the release scripts rather than by the workflows, and has the C++ examples off by default.
When the examples are built standalone against an installed HDF5, the HL, Fortran and C++ branches choose between the shared and static libraries using BUILD_SHARED_LIBS, while the C branch just above them uses H5EXAMPLE_USE_SHARED_LIBS. H5EXAMPLE_USE_SHARED_LIBS is what decides whether the "shared" or the "static" component is requested from find_package, so only the matching HDF5_<linkage>_<lang>_FOUND variables are ever set. BUILD_SHARED_LIBS cannot select a linkage on its own; it can only agree or fail to match. Of its four combinations with H5EXAMPLE_USE_SHARED_LIBS, three produce no observable difference. In the fourth, H5EXAMPLE_USE_SHARED_LIBS=ON with BUILD_SHARED_LIBS unset, the shared branch is not taken and the static branch cannot be, so the HL, Fortran and C++ examples are disabled with "libs not found" even though the libraries are installed and were found. Use H5EXAMPLE_USE_SHARED_LIBS, which is the declared option and is already what the C branch uses. A build driven through config/examples/CTestScript.cmake does not reach the broken combination, because it configures with HDF5Examples/config/cmake/cacheinit.cmake, which forces BUILD_SHARED_LIBS=ON. A direct cmake invocation without that cache file does. In either case the HL, Fortran and C++ examples are off by default, so this is only visible once they are enabled. BUILD_SHARED_LIBS remains documented as a user option in config/examples/HDF5_Examples_options.cmake but no longer influences library selection; that comment should be revisited separately.
mattjala
force-pushed
the
examples-shared-libs-detection
branch
from
August 6, 2026 16:49
c7a81e1 to
089f290
Compare
mattjala
force-pushed
the
examples-shared-libs-detection
branch
from
August 6, 2026 16:50
089f290 to
de4bc7b
Compare
Contributor
bmribler
reviewed
Aug 6, 2026
| Builds driven through `CTestScript.cmake` were not affected, since its cache | ||
| file forces `BUILD_SHARED_LIBS` on. This affected cases where the examples | ||
| were built directly without that cache file. | ||
|
|
Collaborator
There was a problem hiding this comment.
Just curious, is it possible to combine them so that there are no two different things giving the same effect?
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.
The standalone examples build used C++98, but
H5public.hincludes<cinttypes>, which requires C++11. This affected any C++ translation unitincluding
hdf5.h, and did not match the HDF5 C++ library itself, which isbuilt as C++11. The C++ examples did not compile, against either static or
shared HDF5. The examples are now built as C++11.
Only the standalone build was affected. Examples built as part of the HDF5
build inherit the library's own C++ standard.
When built standalone against an installed HDF5, the examples chose between
the shared and static HL, Fortran and C++ libraries using
BUILD_SHARED_LIBS,while the C library used
H5EXAMPLE_USE_SHARED_LIBS. SinceH5EXAMPLE_USE_SHARED_LIBSdetermines which component is requested fromfind_package, and therefore whichHDF5_<linkage>_<lang>_FOUNDvariablesexist,
BUILD_SHARED_LIBScould not select a linkage on its own. WithH5EXAMPLE_USE_SHARED_LIBSon andBUILD_SHARED_LIBSunset, those exampleswere disabled with a "libs not found" message even though the libraries were
installed and had been found. The selection now uses
H5EXAMPLE_USE_SHARED_LIBS, matching the C library.Builds driven through
CTestScript.cmakewere not affected, since its cachefile forces
BUILD_SHARED_LIBSon. This affected cases where the exampleswere built directly without that cache file.
BUILD_SHARED_LIBS remains documented as a user option in
config/examples/HDF5_Examples_options.cmake but no longer influences
library selection in this case. Pending discussion, we may want to remove that variable
or rework this mechanism.