Reputation: 1356
I am working on a QT 5 project and doing my development under MSYS2/Mingw64.
Within that project is a sub-project using Matio, which is compiled into a static .a library.
Matio, with the macros HAVE_HDF5
and MAT73
set to true (1) can support the HDF5 data format, assuming HDF5 is linked in.
I installed the mingw-w64-x86_64-hdf5
package, which is version 1.14.1.2. The resulting library is in D:\msys64\mingw64\lib
.
I am linking this into my project by passing GCC -LD:\msys64\mingw64\lib
as well as LIBS += -lhdf5
in the PRO file. The result is that G++ shows -LD:/msys64/mingw64/lib -lhdf5
in the compilation line.
However, this doesn't work for me. At the final step, it fails everywhere Matio uses HDF5. The first failure is here:
D:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: ../matio/libmatio.a(mat.o): in function `Mat_Open': C:/source/project/matio/mat.c:591:(.text+0xda3): undefined reference to `H5check_version'
I've also checked, and the dll.a file has that function, as well as all the others:
libhdf5_310_dll_d003747.o:
0000000000000000 i .idata$4
0000000000000000 i .idata$5
0000000000000000 i .idata$6
0000000000000000 i .idata$7
0000000000000000 t .text
0000000000000000 I __imp_H5check_version
U _head_libhdf5_310_dll
0000000000000000 T H5check_version
So clearly something is going wrong with the linking in of HDF5, but why? The library exists and GCC is being told to link it in, so what's the problem?
The whole project cannot be posted here, so looking for more general advice if possible.
I suspect that the issue is that HDF5 isn't being linked into the static lib sub-project that uses Matio, and only in the final project. Since it's statically linked it needs HDF5 when building the matio .a file, not later when the executable is built. Just a guess. Doing LIBS += -lhdf5
doesn't seem to do anything to that subproject. That subproject is just built with:
ar -rc libmatio.a mat.o mat4.o mat5.o mat73.o inflate.o endian.o read_data.o matvar_struct.o io.o
Upvotes: 0
Views: 64
Reputation: 1356
The order of the links matters. Counterintuitively, HDF5 must be linked AFTER matio in this case. Also, I noted that trying to directly link via LIBS += libhdf5.a caused issues, as the .dll.a helps with linking in some of hdf5's dependencies like libcurl.
Upvotes: 0