Hi,
The pkg-config file that is shipped by MatIO is incorrect with respect to static linking.
On a Debian sid/unstable system, if I try to to create a static binary for matdump, I get the following:
$ gcc -static matdump.c $(pkg-config --static --libs matio) -lm -o matdump
/usr/bin/ld: /usr/lib/x86_64-linux-gnu/hdf5/serial/lib/libhdf5.a(H5PLint.o) : dans la fonction « H5PL__open » :
(.text+0x46b): avertissement : Using 'dlopen' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/bin/ld: /usr/lib/x86_64-linux-gnu/hdf5/serial/lib/libhdf5.a(H5Z.o) : dans la fonction « H5Z__init_package » :
(.text+0x60f): undefined reference to `SZ_encoder_enabled'
/usr/bin/ld: /usr/lib/x86_64-linux-gnu/hdf5/serial/lib/libhdf5.a(H5Zszip.o) : dans la fonction « H5Z__filter_szip » :
(.text+0xa2): undefined reference to `SZ_BufftoBuffDecompress'
/usr/bin/ld: (.text+0x125): undefined reference to `SZ_BufftoBuffCompress'
collect2: error: ld returned 1 exit status
The issue is that hdf5 depends on libsz, but that is not reflected by the pkg-config output:
$ pkg-config --static --libs matio
-lmatio -L/usr/lib/x86_64-linux-gnu/hdf5/serial/lib -lhdf5 -lz
This is not a problem for dynamic linking, but it bites when doing static linking.
The proper way of dealing with this issue is to use the Requires.private keyword inside the pkg-config file. See for example this guide: https://people.freedesktop.org/~dbn/pkg-config-guide.html
Hence the matio.pc.in file should look like:
prefix=@prefix@
exec_prefix=@exec_prefix@
libdir=@libdir@
includedir=@includedir@
Name: MATIO
Description: MATIO Library
Version: @VERSION@
Libs: -L${libdir} -lmatio
Cflags: -I${includedir}
Requires.private: hdf5 zlib
The Requires.private keyword means that dependencies of hdf5 (and zlib) will be recursively computed by the pkg-config framework when doing static linking (of course you will have to adjust my example a little bit to deal with situations where HDF5 and/or ZLIB support is not built in MatIO).
Best,
Sébastien Villemot
Maintainer of the Debian package for MatIO
Should be fixed as proposed by ee6e04a5. Please confirm if the static linking is successful in your env. Thanks.
Thanks for working on this.
There are two problems with your current commit.
The first one is that the syntax within the Requires.private field is incorrect. There should be a space before and after the >= symbol, otherwise parsing fails.
The second problem is that you left HDF5 and Zlib flags in the Libs and Cflags fields. This is not needed. As long as HDF5 and Zlib are mentionned in the Requires.private fields, pkg-config will take care of adding the necessary flags when doing static linking (and those flags are not needed when doing dynamic linking).
Thanks for your feedback. Plase give b7bd42a5 another try.
There is a typo in the Libs field (a trailing @)
Right. Fixed and force-pushed by 1f3bc4af.
Thanks, it now looks good.