Weird HDF5 exception, only on linked library (C++)

Hello!
I’m a beginner user of HDF5, and I encountered a behavior that I can not explain.
For some context, I’m developing a toolkit for FLASH hydrodynamic simulation code, which produces the hdf5 files for me to read and process.

First, I built HDF5 1.12.2, with MSVS 17.7.4 (MSVC 14.37.32822), via CMake 3.21.3 for VS-Solution generation.
The following CMake options were used, for the purpose of creating a shared library:

Then, I made my own shared library, which should contain the convenient and easy-to-use functions in a concrete application like mine.
For the purpose of illustration, I reduced it to a minimum-breaking example. It consists of a library “dataset_bug_lib” that is linked against HDF5, and an executable “dataset_bug_exec” that is linked against both the HDF5 library and “dataset_bug_lib”.
This contents of this project are the following:

bug.h:

#pragma once

#include "H5Cpp.h"

#include <string>

void bug_function(const H5::H5File& file, const std::string& dataset_name);

bug.cpp:

#include "bug.h"

void bug_function(const H5::H5File& file, const std::string& dataset_name)
{
	H5::DataSet dataset = file.openDataSet(dataset_name);
}

main.cpp:

#include "H5Cpp.h"

#include "bug.h"

void not_bug_function(const H5::H5File& file, const std::string& dataset_name)
{
	H5::DataSet dataset = file.openDataSet(dataset_name);
}

int main()
{
	std::string filename = "lasslab_hdf5_plt_cnt_0148";
	std::string dataset_name = "integer scalars";

	try {
		H5::H5File file(filename, H5F_ACC_RDONLY);

		bug_function(file, dataset_name);

		// not_bug_function(file, dataset_name);
	}
	catch (H5::FileIException error) { error.printErrorStack(); return -1; }
	catch (H5::DataSetIException error) { error.printErrorStack(); return -1; }
	catch (H5::DataSpaceIException error) { error.printErrorStack(); return -1; }
	catch (H5::DataTypeIException error) { error.printErrorStack(); return -1; }

	return 0;
}

CMakeLists.txt:

cmake_minimum_required(VERSION 3.13.0)
set(CMAKE_CXX_STANDARD 20)

set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)

project(DataSet_bug DESCRIPTION "Testing weird dataset crash bug")

#add HDF5 library as an imported target

add_library(h5_lib SHARED IMPORTED GLOBAL)
add_library(h5_cpp_lib SHARED IMPORTED GLOBAL)
set_target_properties(h5_lib PROPERTIES IMPORTED_IMPLIB "${HDF5_LIB}")
set_target_properties(h5_cpp_lib PROPERTIES IMPORTED_IMPLIB "${HDF5_CPP_LIB}")

set(headers ./bug.h)
set(sources ./bug.cpp)
set(incldirs ./)

add_library(dataset_bug_lib SHARED ${headers} ${sources})
install(TARGETS dataset_bug_lib
	ARCHIVE DESTINATION ${CMAKE_INSTALL_PREFIX}
	LIBRARY DESTINATION ${CMAKE_INSTALL_PREFIX}
	RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX})

#link HDF5 libraries
target_include_directories(dataset_bug_lib PUBLIC ${HDF5_INCLUDE_DIR})
target_link_libraries(dataset_bug_lib PUBLIC h5_lib)
target_link_libraries(dataset_bug_lib PUBLIC h5_cpp_lib)

add_executable(dataset_bug_exec "./main.cpp")

target_link_libraries(dataset_bug_exec PUBLIC dataset_bug_lib)

#link HDF5 libraries
target_include_directories(dataset_bug_exec PUBLIC ${HDF5_INCLUDE_DIR})
target_link_libraries(dataset_bug_exec PUBLIC h5_lib)
target_link_libraries(dataset_bug_exec PUBLIC h5_cpp_lib)

This little project is configured in CMake as follows:

And then, upon running the executable, the weird thing happens:

The file “lasslab_hdf5_plt_cnt_0148” is present (a different HDF5 exception is thrown otherwise).
The dataset “integer scalars” is present (as seen in HDFView, and different HDF5 exception is thrown otherwise).

Moreover, if the very same project, along with the HDF library, are built using MinGW-w64 (winlibs-x86_64-posix-seh-gcc-12.1.0-mingw-w64ucrt-10.0.0-r2), this does not happen, and everything works as intended.

Even weirder, if one is to use “not_bug_function” instead, which is identical to the “bug_function” aside from the fact that it is compiled as a part of the “dataset_bug_exec” and not the “dataset_bug_lib”, this error also does not happen. (Of course, inline-ing the bug_function also works)

Before posting, I tried to lookup the exception on the web, however, nothing relevant seems to be found.

Can anyone please point out the root of this weird behavior here?

Thanks in advance.