Repository: georust/netcdf (language: rust)

Issue:
Does not compile in release mode
The cmake command in netcdf-src with `static` feature fails for me on release builds.

Steps to reproduce (in an empty folder)
```shell
cargo init
cargo add netcdf --features static
cargo build # Succeeds
cargo build --release # Fails
```

Output:
```
   Compiling cc v1.0.96
   Compiling pkg-config v0.3.30
   Compiling vcpkg v0.2.15
   Compiling memchr v2.7.2
   Compiling regex-syntax v0.8.3
   Compiling autocfg v1.3.0
   Compiling cfg-if v1.0.0
   Compiling libc v0.2.154
   Compiling semver v1.0.22
   Compiling rawpointer v0.2.1
   Compiling netcdf v0.9.1
   Compiling bitflags v2.5.0
   Compiling libloading v0.7.4
   Compiling num-traits v0.2.19
   Compiling matrixmultiply v0.3.8
   Compiling aho-corasick v1.1.3
   Compiling netcdf-sys v0.6.0
   Compiling cmake v0.1.50
   Compiling libz-sys v1.1.16
   Compiling hdf5-src v0.8.1
   Compiling netcdf-src v0.3.3
   Compiling num-complex v0.4.5
   Compiling num-integer v0.1.46
   Compiling ndarray v0.15.6
   Compiling regex-automata v0.4.6
   Compiling regex v1.10.4
   Compiling hdf5-sys v0.8.1
error: failed to run custom build command for `netcdf-src v0.3.3`

Caused by:
  process didn't exit successfully: `/home/max/dev/bug/target/release/build/netcdf-src-133e7c1c090136f3/build-script-build` (exit status: 101)
  --- stdout
  cargo:rerun-if-changed=build.rs
  CMAKE_TOOLCHAIN_FILE_x86_64-unknown-linux-gnu = None
  CMAKE_TOOLCHAIN_FILE_x86_64_unknown_linux_gnu = None
  HOST_CMAKE_TOOLCHAIN_FILE = None
  CMAKE_TOOLCHAIN_FILE = None
  CMAKE_GENERATOR_x86_64-unknown-linux-gnu = None
  CMAKE_GENERATOR_x86_64_unknown_linux_gnu = None
  HOST_CMAKE_GENERATOR = None
  CMAKE_GENERATOR = None
  CMAKE_PREFIX_PATH_x86_64-unknown-linux-gnu = None
  CMAKE_PREFIX_PATH_x86_64_unknown_linux_gnu = None
  HOST_CMAKE_PREFIX_PATH = None
  CMAKE_PREFIX_PATH = None
  CMAKE_x86_64-unknown-linux-gnu = None
  CMAKE_x86_64_unknown_linux_gnu = None
  HOST_CMAKE = None
  CMAKE = None
  running: cd "/home/max/dev/bug/target/release/build/netcdf-src-e0c5a24fb58674c7/out/build" && CMAKE_PREFIX_PATH="" "cmake" "/home/max/.cargo/registry/src/index.crates.io-6f17d22bba15001f/netcdf-src-0.3.3/source" "-DBUILD_SHARED_LIBS=OFF" "-DNC_FIND_SHARED_LIBS=OFF" "-DBUILD_UTILITIES=OFF" "-DENABLE_EXAMPLES=OFF" "-DENABLE_DAP_REMOTE_TESTS=OFF" "-DENABLE_TESTS=OFF" "-DENABLE_EXTREME_NUMBERS=OFF" "-DENABLE_PARALLEL_TESTS=OFF" "-DENABLE_FILTER_TESTING=OFF" "-DENABLE_BASH_SCRIPT_TESTING=OFF" "-DENABLE_PLUGINS=OFF" "-DPLUGIN_INSTALL_DIR=OFF" "-DHDF5_VERSION=1.10.7" "-DHDF5_C_LIBRARY=hdf5" "-DHDF5_HL_LIBRARY=hdf5_hl" "-DHDF5_INCLUDE_DIR=/home/max/dev/bug/target/release/build/hdf5-src-614e7233f98d8695/out/include" "-DENABLE_NCZARR=OFF" "-DENABLE_DAP=OFF" "-DENABLE_BYTERANGE=OFF" "-DENABLE_DAP_REMOTE_TESTS=OFF" "-DZLIB_ROOT=/home/max/dev/bug/target/release/build/libz-sys-97b733af6dc36c2b/out/include/.." "-DCMAKE_INSTALL_PREFIX=/home/max/dev/bug/target/release/build/netcdf-src-e0c5a24fb58674c7/out" "-DCMAKE_C_FLAGS= -ffunction-sections -fdata-sections -fPIC -m64" "-DCMAKE_C_COMPILER=/usr/bin/cc" "-DCMAKE_CXX_FLAGS= -ffunction-sections -fdata-sections -fPIC -m64" "-DCMAKE_CXX_COMPILER=/usr/bin/c++" "-DCMAKE_ASM_FLAGS= -ffunction-sections -fdata-sections -fPIC -m64" "-DCMAKE_ASM_COMPILER=/usr/bin/cc" "-DCMAKE_BUILD_TYPE=RelWithDebInfo"
  -- The C compiler identification is GNU 13.2.1
  -- The CXX compiler identification is GNU 13.2.1
  -- Detecting C compiler ABI info
  -- Detecting C compiler ABI info - done
  -- Check for working C compiler: /usr/bin/cc - skipped
  -- Detecting C compile features
  -- Detecting C compile features - done
  -- Detecting CXX compiler ABI info
  -- Detecting CXX compiler ABI info - done
  -- Check for working CXX compiler: /usr/bin/c++ - skipped
  -- Detecting CXX compile features
  -- Detecting CXX compile features - done
  -- Performing Test LIBTOOL_HAS_NO_UNDEFINED
  -- Performing Test LIBTOOL_HAS_NO_UNDEFINED - Success
  -- Performing Test CC_HAS_WCONVERSION
  -- Performing Test CC_HAS_WCONVERSION - Success
  -- Performing Test CC_HAS_SHORTEN_64_32
  -- Performing Test CC_HAS_SHORTEN_64_32 - Failed
  -- Using HDF5 C Library: hdf5
  -- Using HDF5 HL LIbrary: hdf5_hl
  -- Found HDF5 libraries version 1.10.7
  -- Performing Test CMAKE_HAVE_LIBC_PTHREAD
  -- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Success
  -- Found Threads: TRUE
  -- Performing Test HAVE_HDF5_ZLIB
  -- Performing Test HAVE_HDF5_ZLIB - Success
  -- Found ZLIB: /home/max/dev/bug/target/release/build/libz-sys-97b733af6dc36c2b/out/lib/libz.a (found version "1.3.1")
  -- HDF5 has zlib.
  -- Performing Test USE_HDF5_SZIP
  -- Performing Test USE_HDF5_SZIP - Failed
  -- Looking for H5Pget_fapl_mpio in hdf5
  -- Looking for H5Pget_fapl_mpio in hdf5 - found
  -- Looking for H5Pset_all_coll_metadata_ops in hdf5
  -- Looking for H5Pset_all_coll_metadata_ops in hdf5 - found
  -- Looking for H5Dread_chunk in hdf5
  -- Looking for H5Dread_chunk in hdf5 - found
  -- Looking for H5Pset_fapl_ros3 in hdf5
  -- Looking for H5Pset_fapl_ros3 in hdf5 - not found
  -- Found CURL: /usr/lib/libcurl.so (found version "8.7.1")
  -- Performing Test HAVE_LIBCURL_766
  -- Performing Test HAVE_LIBCURL_766 - Success
  -- Found Math library: /usr/lib/libm.so
  -- Found Szip: headers at /usr/include, libraries at /usr/lib
  --    library is /usr/lib/libsz.so
  -- Found Bz2: headers at /usr/include, libraries at /usr/lib
  --    library is /usr/lib/libbz2.so
  -- Found Blosc: headers at /usr/include, libraries at /usr/lib
  --    library is /usr/lib/libblosc.so
  -- Found Zstd: headers at /usr/include, libraries at /usr/lib
  --    library is /usr/lib/libzstd.so
  -- Found LibXml2: /usr/lib/libxml2.so (found version "2.12.6")
  -- Found MPI_C: /usr/lib/libmpi.so (found version "3.1")
  -- Found MPI_CXX: /usr/lib/libmpi.so (found version "3.1")
  -- Found MPI: TRUE (found version "3.1")
  -- Enabling use of fill value when NC_ERANGE
  -- Enabling a more relaxed check for NC_EINVALCOORDS
  -- Looking for math.h
  -- Looking for math.h - found
  -- Looking for unistd.h
  -- Looking for unistd.h - found
  -- Looking for alloca.h
  -- Looking for alloca.h - found
  -- Looking for malloc.h
  -- Looking for malloc.h - found
  -- Looking for fcntl.h
  -- Looking for fcntl.h - found
  -- Looking for getopt.h
  -- Looking for getopt.h - found
  -- Looking for locale.h
  -- Looking for locale.h - found
  -- Looking for stdint.h
  -- Looking for stdint.h - found
  -- Looking for stdio.h
  -- Looking for stdio.h - found
  -- Looking for stdlib.h
  -- Looking for stdlib.h - found
  -- Looking for stdarg.h
  -- Looking for stdarg.h - found
  -- Looking for strings.h
  -- Looking for strings.h - found
  -- Looking for signal.h
  -- Looking for signal.h - found
  -- Looking for sys/param.h
  -- Looking for sys/param.h - found
  -- Looking for sys/stat.h
  -- Looking for sys/stat.h - found
  -- Looking for sys/time.h
  -- Looking for sys/time.h - found
  -- Looking for sys/types.h
  -- Looking for sys/types.h - found
  -- Looking for sys/mman.h
  -- Looking for sys/mman.h - found
  -- Looking for sys/resource.h
  -- Looking for sys/resource.h - found
  -- Looking for inttypes.h
  -- Looking for inttypes.h - found
  -- Looking for pstdint.h
  -- Looking for pstdint.h - not found
  -- Looking for endian.h
  -- Looking for endian.h - found
  -- Looking for BaseTsd.h
  -- Looking for BaseTsd.h - not found
  -- Looking for stddef.h
  -- Looking for stddef.h - found
  -- Looking for string.h
  -- Looking for string.h - found
  -- Looking for winsock2.h
  -- Looking for winsock2.h - not found
  -- Looking for ftw.h
  -- Looking for ftw.h - found
  -- Looking for libgen.h
  -- Looking for libgen.h - found
  -- Looking for execinfo.h
  -- Looking for execinfo.h - found
  -- Looking for dirent.h
  -- Looking for dirent.h - found
  -- Looking for time.h
  -- Looking for time.h - found
  -- Looking for dlfcn.h
  -- Looking for dlfcn.h - found
  -- Looking for isfinite
  -- Looking for isfinite - found
  -- Looking for isnan
  -- Looking for isnan - found
  -- Looking for isinf
  -- Looking for isinf - found
  -- Looking for st_blksize
  -- Looking for st_blksize - not found
  -- Looking for alloca
  -- Looking for alloca - found
  -- Looking for snprintf
  -- Looking for snprintf - found
  -- Check size of char
  -- Check size of char - done
  -- Check size of double
  -- Check size of double - done
  -- Check size of float
  -- Check size of float - done
  -- Check size of int
  -- Check size of int - done
  -- Check size of uint
  -- Check size of uint - done
  -- Check size of schar
  -- Check size of schar - failed
  -- Check size of long
  -- Check size of long - done
  -- Check size of long long
  -- Check size of long long - done
  -- Check size of unsigned long long
  -- Check size of unsigned long long - done
  -- Check size of off_t
  -- Check size of off_t - done
  -- Check size of off64_t
  -- Check size of off64_t - done
  -- Check size of short
  -- Check size of short - done
  -- Check size of ushort
  -- Check size of ushort - done
  -- Check size of _Bool
  -- Check size of _Bool - done
  -- Check size of size_t
  -- Check size of size_t - done
  -- Check size of ssize_t
  -- Check size of ssize_t - done
  -- Check size of ptrdiff_t
  -- Check size of ptrdiff_t - done
  -- Check size of uintptr_t
  -- Check size of uintptr_t - done
  -- Check size of __int64
  -- Check size of __int64 - failed
  -- Check size of int64_t
  -- Check size of int64_t - done
  -- Check size of uint64
  -- Check size of uint64 - failed
  -- Check size of unsigned char
  -- Check size of unsigned char - done
  -- Check size of unsigned short int
  -- Check size of unsigned short int - done
  -- Check size of unsigned int
  -- Check size of unsigned int - done
  -- Check size of long long
  -- Check size of long long - done
  -- Check size of unsigned long long
  -- Check size of unsigned long long - done
  -- Check size of uint64_t
  -- Check size of uint64_t - done
  -- Looking for fsync
  -- Looking for fsync - found
  -- Looking for strlcat
  -- Looking for strlcat - found
  -- Looking for strdup
  -- Looking for strdup - found
  -- Looking for strndup
  -- Looking for strndup - found
  -- Looking for strtoll
  -- Looking for strtoll - found
  -- Looking for strcasecmp
  -- Looking for strcasecmp - found
  -- Looking for strtoull
  -- Looking for strtoull - found
  -- Looking for mkstemp
  -- Looking for mkstemp - found
  -- Looking for mktemp
  -- Looking for mktemp - found
  -- Looking for random
  -- Looking for random - found
  -- Looking for gettimeofday
  -- Looking for gettimeofday - found
  -- Looking for MPI_Comm_f2c
  -- Looking for MPI_Comm_f2c - not found
  -- Looking for MPI_Info_f2c
  -- Looking for MPI_Info_f2c - not found
  -- Looking for memmove
  -- Looking for memmove - found
  -- Looking for getpagesize
  -- Looking for getpagesize - found
  -- Looking for sysconf
  -- Looking for sysconf - found
  -- Looking for getrlimit
  -- Looking for getrlimit - found
  -- Looking for _filelengthi64
  -- Looking for _filelengthi64 - not found
  -- Looking for mmap
  -- Looking for mmap - found
  -- Looking for mremap
  -- Looking for mremap - found
  -- Looking for fileno
  -- Looking for fileno - found
  -- Looking for clock_gettime
  -- Looking for clock_gettime - found
  -- Looking for struct timespec
  -- Looking for struct timespec - not found
  -- Looking for atexit
  -- Looking for atexit - found
  -- Performing Test HAVE_MAPANON
  -- Performing Test HAVE_MAPANON - Success
  -- Found m4: /usr/bin/m4
  -- Building Shared Libraries:     OFF
  -- Building netCDF-4:             ON
  -- Building DAP2 Support:         OFF
  -- Building DAP4 Support:         OFF
  -- Building Byte-range Support:   OFF
  -- Building Utilities:            OFF
  -- Using PnetCDF:       OFF
  -- Using Parallel IO:   ON
  -- Build Type:           RELWITHDEBINFO
  -- CMAKE_C_COMPILER:     /usr/bin/cc
  -- CMAKE_C_FLAGS:         -ffunction-sections -fdata-sections -fPIC -m64 -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64
  -- Linking against:      hdf5_hl;hdf5;/usr/lib/libm.so;/home/max/dev/bug/target/release/build/libz-sys-97b733af6dc36c2b/out/lib/libz.a;/usr/lib/libblosc.so;/usr/lib/libzstd.so;/usr/lib/libbz2.so;/usr/lib/libcurl.so;/usr/lib/libxml2.so
  -- # NetCDF C Configuration Summary
  ==============================

  # General
  -------
  NetCDF Version:               4.9.2
  Dispatch Version:       5
  Configured On:                2024-05-04T16:51:41 CEST
  Host System:          x86_64-Linux-6.5.7-273-tkg-linux-tkg-cfs-generic_v3
  Build Directory:      /home/max/dev/bug/target/release/build/netcdf-src-e0c5a24fb58674c7/out/build
  Install Prefix:         /home/max/dev/bug/target/release/build/netcdf-src-e0c5a24fb58674c7/out
  Plugin Install Prefix:  N.A.

  # Compiling Options
  -----------------
  C Compiler:           /usr/bin/cc
  CFLAGS:                        -ffunction-sections -fdata-sections -fPIC -m64 -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -O2 -g -DNDEBUG
  CPPFLAGS:
  LDFLAGS:
  AM_CFLAGS:
  AM_CPPFLAGS:
  AM_LDFLAGS:
  Shared Library:               no
  Static Library:               yes
  Extra libraries:      -lhdf5_hl -lhdf5 -lm -lz -lblosc -lzstd -lbz2 -lcurl -lxml2
  XML Parser:             libxml2

  # Features
  --------
  Benchmarks:           no
  NetCDF-2 API:         yes
  HDF4 Support:         no
  HDF5 Support:         yes
  NetCDF-4 API:         yes
  CDF5 Support:         yes
  NC-4 Parallel Support:        yes
  PnetCDF Support:      no

  DAP2 Support:         no
  DAP4 Support:         no
  Byte-Range Support:   no

  S3 Support:           no

  NCZarr Support:               no
  NCZarr Zip Support:     no

  Diskless Support:     yes
  MMap Support:         yes
  JNA Support:          no
  ERANGE Fill Support:  yes
  Relaxed Boundary Check:       yes

  Multi-Filter Support: yes
  Quantization:         yes
  Logging:              no
  SZIP Write Support:     yes
  Standard Filters:       deflate szip blosc zstd bz2
  ZSTD Support:           yes
  Parallel Filters:       yes


  -- Configuring incomplete, errors occurred!

  --- stderr
  CMake Warning (dev) at CMakeLists.txt:54 (exec_program):
    Policy CMP0153 is not set: The exec_program command should not be called.
    Run "cmake --help-policy CMP0153" for policy details.  Use the cmake_policy
    command to set the policy and suppress this warning.

    Use execute_process() instead.
  Call Stack (most recent call first):
    CMakeLists.txt:56 (getuname)
  This warning is for project developers.  Use -Wno-dev to suppress it.

  CMake Warning (dev) at CMakeLists.txt:54 (exec_program):
    Policy CMP0153 is not set: The exec_program command should not be called.
    Run "cmake --help-policy CMP0153" for policy details.  Use the cmake_policy
    command to set the policy and suppress this warning.

    Use execute_process() instead.
  Call Stack (most recent call first):
    CMakeLists.txt:57 (getuname)
  This warning is for project developers.  Use -Wno-dev to suppress it.

  CMake Warning (dev) at CMakeLists.txt:54 (exec_program):
    Policy CMP0153 is not set: The exec_program command should not be called.
    Run "cmake --help-policy CMP0153" for policy details.  Use the cmake_policy
    command to set the policy and suppress this warning.

    Use execute_process() instead.
  Call Stack (most recent call first):
    CMakeLists.txt:58 (getuname)
  This warning is for project developers.  Use -Wno-dev to suppress it.

  -- HDF5_UTF8_PATHS (HDF5 version 1.10.6+): ON
  >>> Standard Filter: szip
  >>> Standard Filter: blosc
  >>> Standard Filter: zstd
  >>> Standard Filter: bz2
  CMake Error: File /home/max/.cargo/registry/src/index.crates.io-6f17d22bba15001f/netcdf-src-0.3.3/source/h5_test/run_par_tests.sh.in does not exist.
  CMake Error at CMakeLists.txt:1500 (configure_file):
    configure_file Problem configuring file


  CMake Error at CMakeLists.txt:1502 (FILE):
    FILE COPY cannot find
    "/home/max/dev/bug/target/release/build/netcdf-src-e0c5a24fb58674c7/out/build/tmp/run_par_tests.sh":
    No such file or directory.


  CMake Warning at CMakeLists.txt:1642 (MESSAGE):
    ENABLE_FILTER_TESTING requires shared libraries.  Disabling.


  CMake Warning at CMakeLists.txt:1651 (MESSAGE):
    ENABLE_FILTER_TESTING requires shared libraries.  Disabling.


  CMake Warning at CMakeLists.txt:1656 (MESSAGE):
    ENABLE_NCZARR==NO => ENABLE_NCZARR_FILTERS==NO AND
    ENABLE_NCZARR_FILTER_TESTING==NO




  Configuration Summary:


  Building Parallel NetCDF

  Tests Enabled:              OFF

  Compiler:


  thread 'main' panicked at /home/max/.cargo/registry/src/index.crates.io-6f17d22bba15001f/cmake-0.1.50/src/lib.rs:1098:5:

  command did not execute successfully, got: exit status: 1

  build script failed, must exit now
  note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
```



Discussion / hints:
A workaround is to force a debug-build of hdf5-src:

```toml
[profile.release.package.hdf5-src]
opt-level = 0
```
Seems strange that the debug build of hdf5-src should fix this problem. Is the parallel flag enabled only for the release build of hdf5?
You should be able to run `cargo update netcdf-src` and get the fix
Thanks,  it compiles now, but as soon as I use e.g. `netcdf::open`, the linking fails:

```
error: linking with `cc` failed: exit status: 1
  |
  = note: LC_ALL="C" PATH="/home/max/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/bin:/home/max/.cache/zsh/zinit/polaris/bin:/home/max/.nix-profile/bin:/nix/var/nix/profiles/default/bin:/home/max/.nix-profile/bin:/nix/var/nix/profiles/default/bin:/usr/local/sbin:/usr/local/bin:/usr/bin:/opt/android-sdk/platform-tools:/var/lib/flatpak/exports/bin:/usr/lib/jvm/default/bin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl:/opt/rocm/bin:/usr/lib/rustup/bin:/opt/android-sdk/platform-tools:/home/max/.cargo/bin:/home/max/.local/bin" VSLANG="1033" "cc" "-m64" "/tmp/rustcv55eTS/symbols.o" "/home/max/dev/bug/target/release/deps/bug-a2b8f3e61be9efc4.bug.ccaa775bfa9f94d7-cgu.0.rcgu.o" "/home/max/dev/bug/target/release/deps/bug-a2b8f3e61be9efc4.2do8gvq4tu6jf2q2.rcgu.o" "-Wl,--as-needed" "-L" "/home/max/dev/bug/target/release/deps" "-L" "/home/max/dev/bug/target/release/build/netcdf-src-0f716cb9ba04d569/out/lib" "-L" "/home/max/dev/bug/target/release/build/hdf5-src-614e7233f98d8695/out/lib" "-L" "/home/max/dev/bug/target/release/build/libz-sys-97b733af6dc36c2b/out/lib" "-L" "/home/max/dev/bug/target/release/build/libz-sys-97b733af6dc36c2b/out/lib" "-L" "/home/max/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-Wl,-Bstatic" "/home/max/dev/bug/target/release/deps/libnetcdf-54d0061f1408d96a.rlib" "/home/max/dev/bug/target/release/deps/libbitflags-e1edd608d2279ef5.rlib" "/home/max/dev/bug/target/release/deps/libndarray-a520037548548015.rlib" "/home/max/dev/bug/target/release/deps/libmatrixmultiply-77af54bfaf3802cc.rlib" "/home/max/dev/bug/target/release/deps/libnum_complex-eecdf8110d69816a.rlib" "/home/max/dev/bug/target/release/deps/libnum_integer-72aa4e2196cd81c4.rlib" "/home/max/dev/bug/target/release/deps/libnum_traits-e1c3e3ffc27f3447.rlib" "/home/max/dev/bug/target/release/deps/librawpointer-75fd1a582b448a5f.rlib" "/home/max/dev/bug/target/release/deps/libnetcdf_sys-076c07e3415d6306.rlib" "/home/max/dev/bug/target/release/deps/libnetcdf_src-593ebe26b88c6da0.rlib" "/home/max/dev/bug/target/release/deps/libhdf5_sys-142811e55ce0bac4.rlib" "/home/max/dev/bug/target/release/deps/liblibc-8fe09481f39ba46e.rlib" "/home/max/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd-2d08990d644ac786.rlib" "/home/max/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libpanic_unwind-6f2d4ec7ff80253d.rlib" "/home/max/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libobject-c194d68892442324.rlib" "/home/max/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libmemchr-9a71c52c5946f83b.rlib" "/home/max/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libaddr2line-ae9aec4ce2dabc4f.rlib" "/home/max/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libgimli-6a207457d27610cc.rlib" "/home/max/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_demangle-fb1d2514710eef16.rlib" "/home/max/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd_detect-e36e7ed4b08caeac.rlib" "/home/max/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libhashbrown-9e8dafdf0a1b7ecd.rlib" "/home/max/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_std_workspace_alloc-b218f37fe3c9ce2e.rlib" "/home/max/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libminiz_oxide-20c30954fd9b5ef4.rlib" "/home/max/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libadler-6d3dfaf536d51163.rlib" "/home/max/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libunwind-cb4ce50789112af8.rlib" "/home/max/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcfg_if-9897980a3b548e05.rlib" "/home/max/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/liblibc-b7bd4d010c784af2.rlib" "/home/max/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/liballoc-6d4515df28ba3369.rlib" "/home/max/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_std_workspace_core-e28568c1a21499f7.rlib" "/home/max/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcore-eedf3675950a13c2.rlib" "/home/max/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcompiler_builtins-715e69127681e2e0.rlib" "-Wl,-Bdynamic" "-lgcc_s" "-lutil" "-lrt" "-lpthread" "-lm" "-ldl" "-lc" "-Wl,--eh-frame-hdr" "-Wl,-z,noexecstack" "-L" "/home/max/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-o" "/home/max/dev/bug/target/release/deps/bug-a2b8f3e61be9efc4" "-Wl,--gc-sections" "-pie" "-Wl,-z,relro,-z,now" "-Wl,-O1" "-Wl,--strip-debug" "-nodefaultlibs"
  = note: /usr/bin/ld: /home/max/dev/bug/target/release/deps/libnetcdf_sys-076c07e3415d6306.rlib(hdf5create.c.o): in function `nc4_create_file':
          /home/max/.cargo/registry/src/index.crates.io-6f17d22bba15001f/netcdf-src-0.3.4/source/libhdf5/hdf5create.c:205:(.text.NC4_create+0x3a3): undefined reference to `H5Pset_all_coll_metadata_ops'
          /usr/bin/ld: /home/max/.cargo/registry/src/index.crates.io-6f17d22bba15001f/netcdf-src-0.3.4/source/libhdf5/hdf5create.c:207:(.text.NC4_create+0x3ba): undefined reference to `H5Pset_coll_metadata_write'
          collect2: error: ld returned 1 exit status

  = note: some `extern` functions couldn't be found; some native libraries may need to be installed or have their path specified
  = note: use the `-l` flag to specify native libraries to link
  = note: use the `cargo:rustc-link-lib` directive to specify the native libraries to link with Cargo (see https://doc.rust-lang.org/cargo/reference/build-scripts.html#rustc-link-lib)
```

I suspect that this is an upstream problem in hdf5-src and it doesn't set the correct flags in release builds.
This seems like two versions of `hdf5` are installed, and the wrong one is linked. This could either happen on the rust side, or by cmake when building netcdf-c. Do you have a way for me to replicate your environment?
That was a pointer in the right direction. I do have `hdf5-openmpi` 1.14.3 installed on my system (Arch Linux) as a dependency of FreeCAD. When I uninstall that and `cargo clean`, the release build works! So it looks like the system installed `hdf5` is preferred over the statically built one during linking. This does not trigger for unoptimized builds since there `_d` is added to the library name.

Fix patch:
diff --git a/netcdf-src/build.rs b/netcdf-src/build.rs
index 1d48035..d979a1c 100644
--- a/netcdf-src/build.rs
+++ b/netcdf-src/build.rs
@@ -27,8 +27,19 @@ fn main() {
     println!("cargo:rerun-if-changed=build.rs");
 
     let hdf5_incdir = std::env::var("DEP_HDF5_INCLUDE").unwrap();
-    let hdf5_lib = std::env::var("DEP_HDF5_LIBRARY").unwrap();
-    let hdf5_hl_lib = std::env::var("DEP_HDF5_HL_LIBRARY").unwrap();
+    let mut hdf5_lib = std::env::var("DEP_HDF5_LIBRARY").unwrap();
+    let mut hdf5_hl_lib = std::env::var("DEP_HDF5_HL_LIBRARY").unwrap();
+
+    #[cfg(unix)]
+    {
+        let hdf5_root = format!("{hdf5_incdir}/../");
+        let mut hdf5_libdir = format!("{hdf5_root}/lib/");
+        if !std::path::Path::new(&hdf5_libdir).exists() {
+            hdf5_libdir = format!("{hdf5_root}/lib64/");
+        }
+        hdf5_lib = format!("{hdf5_libdir}/{hdf5_lib}.a");
+        hdf5_hl_lib = format!("{hdf5_libdir}/{hdf5_hl_lib}.a");
+    }
 
     let hdf5_version = get_hdf5_version();
 
diff --git a/netcdf-src/source b/netcdf-src/source
index cbf1282..230ffaf 160000
--- a/netcdf-src/source
+++ b/netcdf-src/source
@@ -1,1 +1,1 @@
-Subproject commit cbf128203297f5a990f37b8c28f45455292d5e7b
+Subproject commit 230ffaf4eb8534a3b8fac3eb4be8e88cf6d61ccd


Test patch: