StrawberryPerl / build-extlibs

16 stars 11 forks source link

hdf4 compilation status #11

Closed shawnlaffan closed 1 year ago

shawnlaffan commented 1 year ago

TLDR: libhdf4 compilation seems reasonably complex. It appears there are conflicts between static and shared libraries. Hopefully someone more knowledgeable about such things can chime in.

build commands and modifications from the repo

This build is using HDF 4.2.15, which is the most recent release. The StrawberryPerl/build-extlibs repo currently targets 4.2.14.

I've modified my version of the build script to not build fortran. This is under the assumption compilation of fortran code using hdf4 is not needed, and also because the HDF FAQ suggests not to for shared builds: https://docs.hdfgroup.org/archive/support/products/hdf4/HDF-FAQ.html#11share . It seems unrelated to the failures but does make things a little faster.

I have updated the code to append to CMakeLists.txt wrapped in an if condition to allow it to be skipped using an env var. It makes no apparent difference if it is excluded or not, but the last four need to be skipped if fortran is disabled.

COPYING.txt is not in the distribution now.

# ----------------------------------------------------------------------------
hdf-*)
cd $WRKDIR/$PACK
if [ -z "${NO_UPDATE_CMAKE_HDF4}" ]; then
echo "IF (BUILD_SHARED_LIBS)" >> CMakeLists.txt
echo "SET_TARGET_PROPERTIES (\${HDF4_SRC_LIBSH_TARGET}             PROPERTIES SUFFIX $DLLSUFFIX.dll)">> CMakeLists.txt
echo "SET_TARGET_PROPERTIES (\${HDF4_MF_XDR_LIBSH_TARGET}          PROPERTIES SUFFIX $DLLSUFFIX.dll)">> CMakeLists.txt
echo "SET_TARGET_PROPERTIES (\${HDF4_MF_LIBSH_TARGET}              PROPERTIES SUFFIX $DLLSUFFIX.dll)">> CMakeLists.txt
##echo "SET_TARGET_PROPERTIES (\${HDF4_MF_FCSTUB_LIBSH_TARGET}       PROPERTIES SUFFIX $DLLSUFFIX.dll)">> CMakeLists.txt
##echo "SET_TARGET_PROPERTIES (\${HDF4_MF_FORTRAN_LIBSH_TARGET}      PROPERTIES SUFFIX $DLLSUFFIX.dll)">> CMakeLists.txt
##echo "SET_TARGET_PROPERTIES (\${HDF4_SRC_FCSTUB_LIBSH_TARGET}      PROPERTIES SUFFIX $DLLSUFFIX.dll)">> CMakeLists.txt
##echo "SET_TARGET_PROPERTIES (\${HDF4_SRC_FORTRAN_LIBSH_TARGET}     PROPERTIES SUFFIX $DLLSUFFIX.dll)">> CMakeLists.txt
echo "ENDIF ()" >> CMakeLists.txt
fi
mkdir MY_BUILD
cd MY_BUILD
#  cp ../COPYING.txt ./
xxrun cmake -G 'Unix Makefiles' -DBUILD_SHARED_LIBS=ON -DCMAKE_INSTALL_PREFIX=$OUT \
                                                       -DBUILD_SHARED_LIBS=ON \
                                                       -DHDF4_BUILD_XDR_LIB=OFF \
                                                       -DHDF4_ENABLE_SZIP_SUPPORT=ON \
                                                       -DHDF4_ENABLE_SZIP_ENCODING=ON \
                                                       -DHDF4_ENABLE_JPEG_LIB_SUPPORT=ON \
                                                       -DHDF4_ENABLE_Z_LIB_SUPPORT=ON \
                                                       -DHDF4_BUILD_FORTRAN=OFF \
                                                       -DHDF4_BUILD_TOOLS=OFF \
                                                       -DHDF4_BUILD_UTILS=OFF \
                                                       -DHDF4_BUILD_EXAMPLES=OFF \
                                                       -DHDF4_NO_PACKAGES=ON \
                                                       -DHDF4_BUILD_EXAMPLES=OFF \
                                                       -DHDF4_NO_PACKAGES=ON \
                                                       -DHDF4_ENABLE_NETCDF=OFF \
                                                       -DDISABLE_PDB_FILES=ON \
                                                       -DSZIP_INCLUDE_DIR=$OUT/include \
                                                       -DSZIP_LIBRARY=$OUT/lib/libsz.dll.a \
                                                       ..
xxrun gmake
xxrun gmake install
# names:
# cp hdf_fcstub-shared.dll.a    libhdf_fcstub.dll.a
# cp hdf_fortran-shared.dll.a   libhdf_fortran.dll.a
# cp hdf-shared.dll.a           libhdf.dll.a
# cp mfhdf_fcstub-shared.dll.a  libmfhdf_fcstub.dll.a
# cp mfhdf_fortran-shared.dll.a libmfhdf_fortran.dll.a
# cp mfhdf-shared.dll.a         libmfhdf.dll.a
;;

build errors

Build errors are below.

So far as I can tell they are issues with static libs being loaded into dynamic libs.
https://stackoverflow.com/questions/66314384/undefined-reference-to-imp-in-minwg https://stackoverflow.com/questions/10059200/how-do-i-fix-undefined-reference-to-imp

Fixing such issues needs different expertise to mine. Hopefully someone can chime in with a solution, or a recommendation it be reported upstream.

(Changing the -DSZIP_LIBRARY=$OUT/lib/libsz.dll.a to point to .../bin/libsz.dll had no effect).

[ 50%] Linking C shared library ../../bin/hdf.dll
z:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles/h
df-shared.dir/objects.a(atom.c.obj): in function `HAinit_group':
C:/spbuild/extlib/_bhdf4__.src/hdf-4.2.15/hdf/src/atom.c:92: undefined reference to `__imp_error_top'
z:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles/h
df-shared.dir/objects.a(atom.c.obj): in function `HAdestroy_group':
C:/spbuild/extlib/_bhdf4__.src/hdf-4.2.15/hdf/src/atom.c:165: undefined reference to `__imp_error_top'
z:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles/h
df-shared.dir/objects.a(atom.c.obj): in function `HAregister_atom':
C:/spbuild/extlib/_bhdf4__.src/hdf-4.2.15/hdf/src/atom.c:230: undefined reference to `__imp_error_top'
z:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles/h
df-shared.dir/objects.a(atom.c.obj): in function `HAPatom_object':
C:/spbuild/extlib/_bhdf4__.src/hdf-4.2.15/hdf/src/atom.c:298: undefined reference to `__imp_error_top'
z:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles/h
df-shared.dir/objects.a(atom.c.obj): in function `HAatom_group':
C:/spbuild/extlib/_bhdf4__.src/hdf-4.2.15/hdf/src/atom.c:358: undefined reference to `__imp_error_top'
z:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles/h
df-shared.dir/objects.a(atom.c.obj):C:/spbuild/extlib/_bhdf4__.src/hdf-4.2.15/hdf/src/atom.c:399: more unde
fined references to `__imp_error_top' follow
collect2.exe: error: ld returned 1 exit status
gmake[2]: *** [hdf/src/CMakeFiles/hdf-shared.dir/build.make:1039: bin/hdf.dll] Error 1
gmake[1]: *** [CMakeFiles/Makefile2:1058: hdf/src/CMakeFiles/hdf-shared.dir/all] Error 2
gmake: *** [makefile:146: all] Error 2
######## retval=FAILURE
######## gonna launch: gmake install
Consolidate compiler generated dependencies of target xdr-static
[  2%] Built target xdr-static
Consolidate compiler generated dependencies of target xdr-shared
[  4%] Built target xdr-shared
Consolidate compiler generated dependencies of target hdf-static
[ 27%] Built target hdf-static
Consolidate compiler generated dependencies of target hdf-shared
[ 27%] Linking C shared library ../../bin/hdf.dll
z:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles/h
df-shared.dir/objects.a(atom.c.obj): in function `HAinit_group':
C:/spbuild/extlib/_bhdf4__.src/hdf-4.2.15/hdf/src/atom.c:92: undefined reference to `__imp_error_top'
z:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles/h
df-shared.dir/objects.a(atom.c.obj): in function `HAdestroy_group':
C:/spbuild/extlib/_bhdf4__.src/hdf-4.2.15/hdf/src/atom.c:165: undefined reference to `__imp_error_top'
z:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles/h
df-shared.dir/objects.a(atom.c.obj): in function `HAregister_atom':
C:/spbuild/extlib/_bhdf4__.src/hdf-4.2.15/hdf/src/atom.c:230: undefined reference to `__imp_error_top'
z:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles/h
df-shared.dir/objects.a(atom.c.obj): in function `HAPatom_object':
C:/spbuild/extlib/_bhdf4__.src/hdf-4.2.15/hdf/src/atom.c:298: undefined reference to `__imp_error_top'
z:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles/h
df-shared.dir/objects.a(atom.c.obj): in function `HAatom_group':
C:/spbuild/extlib/_bhdf4__.src/hdf-4.2.15/hdf/src/atom.c:358: undefined reference to `__imp_error_top'
z:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles/h
df-shared.dir/objects.a(atom.c.obj):C:/spbuild/extlib/_bhdf4__.src/hdf-4.2.15/hdf/src/atom.c:399: more unde
fined references to `__imp_error_top' follow
collect2.exe: error: ld returned 1 exit status
gmake[2]: *** [hdf/src/CMakeFiles/hdf-shared.dir/build.make:1039: bin/hdf.dll] Error 1
gmake[1]: *** [CMakeFiles/Makefile2:1058: hdf/src/CMakeFiles/hdf-shared.dir/all] Error 2
gmake: *** [makefile:146: all] Error 2
######## retval=FAILURE
shawnlaffan commented 1 year ago

Update: Starting afresh and limiting the changes to removal of the fortran components and the duplicate -DBUILD_SHARED_LIBS=ON and using Unix makefiles with gmake produces a working build. The use of gmake might be unnecessary and the duplicate shared libs call might have no effect, but so long as it works...

diff --git a/build.sh b/build.sh
index 56a5af9..c4bfddb 100755
--- a/build.sh
+++ b/build.sh
@@ -1162,10 +1162,10 @@ echo "IF (BUILD_SHARED_LIBS)" >> CMakeLists.txt
 echo "SET_TARGET_PROPERTIES (\${HDF4_SRC_LIBSH_TARGET}             PROPERTIES SUFFIX $DLLSUFFIX.dll)">> CMakeLists.txt
 echo "SET_TARGET_PROPERTIES (\${HDF4_MF_XDR_LIBSH_TARGET}          PROPERTIES SUFFIX $DLLSUFFIX.dll)">> CMakeLists.txt
 echo "SET_TARGET_PROPERTIES (\${HDF4_MF_LIBSH_TARGET}              PROPERTIES SUFFIX $DLLSUFFIX.dll)">> CMakeLists.txt
-echo "SET_TARGET_PROPERTIES (\${HDF4_MF_FCSTUB_LIBSH_TARGET}       PROPERTIES SUFFIX $DLLSUFFIX.dll)">> CMakeLists.txt
-echo "SET_TARGET_PROPERTIES (\${HDF4_MF_FORTRAN_LIBSH_TARGET}      PROPERTIES SUFFIX $DLLSUFFIX.dll)">> CMakeLists.txt
-echo "SET_TARGET_PROPERTIES (\${HDF4_SRC_FCSTUB_LIBSH_TARGET}      PROPERTIES SUFFIX $DLLSUFFIX.dll)">> CMakeLists.txt
-echo "SET_TARGET_PROPERTIES (\${HDF4_SRC_FORTRAN_LIBSH_TARGET}     PROPERTIES SUFFIX $DLLSUFFIX.dll)">> CMakeLists.txt
+#echo "SET_TARGET_PROPERTIES (\${HDF4_MF_FCSTUB_LIBSH_TARGET}       PROPERTIES SUFFIX $DLLSUFFIX.dll)">> CMakeLists.txt
+#echo "SET_TARGET_PROPERTIES (\${HDF4_MF_FORTRAN_LIBSH_TARGET}      PROPERTIES SUFFIX $DLLSUFFIX.dll)">> CMakeLists.txt
+#echo "SET_TARGET_PROPERTIES (\${HDF4_SRC_FCSTUB_LIBSH_TARGET}      PROPERTIES SUFFIX $DLLSUFFIX.dll)">> CMakeLists.txt
+#echo "SET_TARGET_PROPERTIES (\${HDF4_SRC_FORTRAN_LIBSH_TARGET}     PROPERTIES SUFFIX $DLLSUFFIX.dll)">> CMakeLists.txt
 ###old
 #echo "SET_TARGET_PROPERTIES (\${HDF4_SRC_LIB_NAME} PROPERTIES SUFFIX $DLLSUFFIX.dll)">> CMakeLists.txt
 #echo "SET_TARGET_PROPERTIES (\${HDF4_MF_XDR_LIB_TARGET} PROPERTIES SUFFIX $DLLSUFFIX.dll)">> CMakeLists.txt
@@ -1178,14 +1178,13 @@ echo "ENDIF ()" >> CMakeLists.txt
 mkdir MY_BUILD
 cd MY_BUILD
 cp ../COPYING.txt ./
-xxrun cmake -G 'MSYS Makefiles' -DBUILD_SHARED_LIBS=ON -DCMAKE_INSTALL_PREFIX=$OUT \
-                                                       -DBUILD_SHARED_LIBS=ON \
+xxrun cmake -G 'Unix Makefiles' -DBUILD_SHARED_LIBS=ON -DCMAKE_INSTALL_PREFIX=$OUT \
                                                        -DHDF4_BUILD_XDR_LIB=ON \
                                                        -DHDF4_ENABLE_SZIP_SUPPORT=ON \
                                                        -DHDF4_ENABLE_SZIP_ENCODING=ON \
                                                        -DHDF4_ENABLE_JPEG_LIB_SUPPORT=ON \
                                                        -DHDF4_ENABLE_Z_LIB_SUPPORT=ON \
-                                                       -DHDF4_BUILD_FORTRAN=ON \
+                                                       -DHDF4_BUILD_FORTRAN=OFF \
                                                        -DHDF4_BUILD_TOOLS=OFF \
                                                        -DHDF4_BUILD_UTILS=OFF \
                                                        -DHDF4_BUILD_EXAMPLES=OFF \
@@ -1194,8 +1193,8 @@ xxrun cmake -G 'MSYS Makefiles' -DBUILD_SHARED_LIBS=ON -DCMAKE_INSTALL_PREFIX=$O
                                                        -DSZIP_INCLUDE_DIR=$OUT/include \
                                                        -DSZIP_LIBRARY=$OUT/lib/libsz.dll.a \
                                                        ..
-xxrun make
-xxrun make install
+xxrun gmake
+xxrun gmake install
 # names:
 # cp hdf_fcstub-shared.dll.a    libhdf_fcstub.dll.a
 # cp hdf_fortran-shared.dll.a   libhdf_fortran.dll.a
diff --git a/sources.list b/sources.list
index 35c9634..a293da5 100755
--- a/sources.list
+++ b/sources.list
@@ -320,6 +320,7 @@ http://www.hdfgroup.org/ftp//HDF/prev-releases/HDF4.2.11/src/hdf-4.2.11.tar.gz
 http://www.hdfgroup.org/ftp//HDF/prev-releases/HDF4.2.1/src/hdf-4.2.11.tar.gz
 https://support.hdfgroup.org/ftp/HDF/releases/HDF4.2.12/src/hdf-4.2.12.tar.gz
 https://support.hdfgroup.org/ftp/HDF/releases/HDF4.2.14/src/hdf-4.2.14.tar.gz
+https://support.hdfgroup.org/ftp/HDF/releases/HDF4.2.15/src/hdf-4.2.15.tar.gz

 #URL http://www.netlib.org/lapack/
 http://www.netlib.org/lapack/lapack-3.6.0.tgz
shawnlaffan commented 1 year ago

@mohawk2 - is there anything in PDL that needs the fortran interface to HDF4?

shawnlaffan commented 1 year ago

Sorry but this still needs work. The successful build was with HDF 4.2.14, for which the logs show it is not finding szip. The build with 4.2.15 does find szip but then throws the errors above.

shawnlaffan commented 1 year ago

Updating the patch files for 4.2.15 gets compilation working. This is a mix of the existing patches for 4.2.14 and the patches in use for MSYS2 packaging.

mohawk2 commented 1 year ago

@mohawk2 - is there anything in PDL that needs the fortran interface to HDF4?

Not to my knowledge!

shawnlaffan commented 1 year ago

PR #12 merged, so closing