Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue linking to static lib hdf5 with szip support #324

Closed
bartoli opened this issue Oct 31, 2016 · 5 comments
Closed

Issue linking to static lib hdf5 with szip support #324

bartoli opened this issue Oct 31, 2016 · 5 comments

Comments

@bartoli
Copy link

bartoli commented Oct 31, 2016

If i try to build netcdf with a static version of hdf5 that has szip support, I get errors at
CHECK_LIBRARY_EXISTS(${HDF5_C_LIBRARY} H5free_memory "" HDF5_HAS_H5FREE)
CHECK_LIBRARY_EXISTS(${HDF5_C_LIBRARY} H5Pset_libver_bounds "" HDF5_HAS_LIBVER_BOUNDS)
of CMakeLists.txt. Because szip symbols are not found at link time

Not far after that, there is the test of dependency of hdf5 to szip. Couldn't that test be put before the CHECK_LIBRARY_EXISTS, and in the IF(SZIP), adding something like CMAKE_REQUIRED_LIBRARIES += szip, so the tests that build hdf5 also link szip?

It might not be this trivial, as the SZIP tests too does a CHECK_LIBRARY_EXISTS, so this one might fail too.

@WardF
Copy link
Member

WardF commented Oct 31, 2016

Thanks for pointing this out; your suggestion is a good one, I'll see if it's that simple (feel free to try to beat me to the punch with a pull request!). In the meantime, you can use the NC_EXTRA_DEPS option to specify additional libraries to link against; you should be able to pass it sz (or szip, I forget which) and have it link against szip.

@WardF WardF added this to the 4.4.1.1 milestone Oct 31, 2016
@WardF WardF self-assigned this Oct 31, 2016
@bartoli
Copy link
Author

bartoli commented Nov 2, 2016

To complement the issue, the same thing happens if HDF5 is built with zlib support, so the same kind of modification would need to be added for zlib

@WardF
Copy link
Member

WardF commented Nov 10, 2016

Ok, while this error still makes sense on paper and will still be addressed, it is worth noting that I cannot replicate this issue. The cmake system as it stands does not throw an error when building as described in the original report. I'd like to figure out why; what version of cmake are you using?

@WardF
Copy link
Member

WardF commented Nov 10, 2016

Ok, I'm having problems replicating this, and we fall into a chicken-and-the-egg issue; szip should only be checked for if the hdf5 library requires it, and we can't check if the hdf5 library requires it, when using static libraries, without specifying it. Given that I can't replicate this, I wonder how broad the scope of this issue is. What is your OS and cmake version?

I'm able to get things to work by specifying -DCMAKE_EXTRA_DEPS="dl sz z m", combined with moving the check for libraries specified by NC_EXTRA_DEPS above checks for hdf5 and such. This may be the best we can accomplish for now.

@bartoli
Copy link
Author

bartoli commented Nov 14, 2016

I am using cmake 3.2.3 on windows.
I am using custom built szip, hdf5, and am custom-building netcdf. All those three are built as static libraries, so they will be statically linked in the shared GDAL i build afterwards.

Indeed there is a issue with what to test first. SZIP should be tested only if hdf5 needs it, but hdf5 tests can not be built if we don't provide szip and it needs it. SZIP presence can still be tested without the need for HDF5. I would say that if USE_SZIP=ON (and USE_HDF5=ON), then it can be justified to test SZIP presence first without yet searching if we want to link to a HDF5 that needs it. Then if a SZIP is found, adding it to the link list during the duration of HDF5 tests should not hurt; it will just have no effect if HDF5 doesn't need it.

In my personal case, i only need netcdf static library, and this seemed only to generate issues to me when building the tests packaged in netcdf. I disabled their build and i am not disturbed anymore, i just provide needed include paths and libraries on cmake command line (+ a sed in CMakeLists because my szip livbrary is libszip and not sz)

Part of my build script :

  export SZIP_INSTALL=$ENV_SZIP_PATHM

  echo "set( HDF5_C_LIBRARY         \"$ENV_HDF5_PATHM/lib/libhdf5.lib\"    )" >  hdf5-config.cmake
  echo "set( HDF5_LIBRARY         \"$ENV_HDF5_PATHM/lib/libhdf5.lib\"    )" >> hdf5-config.cmake
  echo "set( HDF5_HL LIBRARY      \"$ENV_HDF5_PATHM/lib/libhdf5_hl.lib\" )" >> hdf5-config.cmake
  echo "set( HDF5_INCLUDE_DIR \"$ENV_HDF5_PATHM/include\"            )" >> hdf5-config.cmake
  echo "set( HDF5_VERSION     \"$ENV_HDF5_VERSION\"                  )" >> hdf5-config.cmake
  echo "set( HDF5_ROOT        \"$ENV_HDF5_PATHM\"                    )" >> hdf5-config.cmake

  #export INCLUDE="$ENV_CURL_PATHM/include;$INCLUDE"
  export LIB="$ENV_SZIP_PATHM/lib;$ENV_ZLIB_PATHM/lib;$ENV_CURL_PATHM/lib;$ENV_HDF5_PATHM/lib;$LIB"
  export PATH=$ENV_ZLIB_PATH/bin:$ENV_CURL_PATH/bin:$PATH
  sed -e "s/NAMES sz/NAMES libszip sz/" -i CMakeLists.txt 

  cmake -G "NMake Makefiles" --verbose \
   -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=OFF -DBUILD_TESTING=OFF -DBUILD_TESTSETS=OFF -DBUILD_UTILITIES=OFF \
   -DENABLE_TESTS=OFF -DENABLE_DAP_REMOTE_TESTS=OFF -DBUILD_TESTING=OFF -DBUILD_TESTING_STATIC=OFF -DBUILD_TESTING_SHARED=OFF \
   -DCMAKE_INSTALL_PREFIX=$instm \
   -DZLIB_LIBRARY=$ENV_ZLIB_PATHM/lib/zdll.lib -DZLIB_INCLUDE_DIR=$ENV_ZLIB_PATHM/include \
   -DCURL_LIBRARY=$ENV_CURL_PATHM/lib/libcurl_imp.lib -DCURL_INCLUDE_DIR=$ENV_CURL_PATHM/include \
   -DUSE_SZIP=ON \
   -DUSE_HDF5=ON -DHDF5_DIR=. \
   -DENABLE_DAP=ON \
   -DCMAKE_REQUIRED_LIBRARIES="libszip;zdll;libhdf5;libhdf5_hl;libcurl_imp" \
  . || exit 1
  nmake /U VERBOSE=1


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
No open projects
Development

No branches or pull requests

2 participants