netcdf-c icon indicating copy to clipboard operation
netcdf-c copied to clipboard

Link error when compiling NCZhdf5filters.o on MinGW64 with netCDF 4.9.0

Open Alexander-Barth opened this issue 3 years ago • 5 comments

I am still trying to update NetCDF for Julia users on Windows. In this test, I tried native compilation on Windows (using the MinGW64 toolchain from MSYS2).

NetCDF is configured as:

./configure --disable-testsets  --enable-shared  --disable-static  --disable-dap-remote-tests
make LDFLAGS=" -no-undefined -Wl,--export-all-symbols"

The MinGW64 compiler version is:

$ gcc --version
gcc.exe (Rev2, Built by MSYS2 project) 12.1.0
Copyright (C) 2022 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

The full error message is:

make[3]: Entering directory '/home/Alexander Barth/netcdf-c-2/plugins'
/bin/sh ../libtool  --tag=CC   --mode=link gcc  -fno-strict-aliasing   -module -avoid-version -shared -export-dynamic -rpath /home/Alexander Barth/netcdf-c-2/plugins -no-undefined -no-undefined -Wl,--export-all-symbols -o lib__nczhdf5filters.la -rpath /home/Alexander Barth/netcdf-c-2/plugins/plugindir NCZhdf5filters.lo  -lhdf5_hl -lhdf5 -lm -lz -lsz -lbz2 -lzstd -lxml2 -lcurl
libtool: link: rm -fr  .libs/lib__nczhdf5filters.dll.a
libtool: link: gcc -shared  .libs/NCZhdf5filters.o   -lhdf5_hl -lhdf5 -lz -lsz -lbz2 -lzstd -lxml2 -lcurl  -Wl,--export-all-symbols   -o .libs/lib__nczhdf5filters.dll -Wl,--enable-auto-image-base -Xlinker --out-implib -Xlinker .libs/lib__nczhdf5filters.dll.a
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: .libs/NCZhdf5filters.o:NCZhdf5filters:(.text+0x1a24): undefined reference to `nc_inq_var'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: .libs/NCZhdf5filters.o:NCZhdf5filters:(.text+0x1a5a): undefined reference to `nc_inq_type'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: .libs/NCZhdf5filters.o:NCZhdf5filters:(.text+0x2350): undefined reference to `nc_inq_var'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: .libs/NCZhdf5filters.o:NCZhdf5filters:(.text+0x2386): undefined reference to `nc_inq_type'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: .libs/NCZhdf5filters.o:NCZhdf5filters:(.text+0x2423): undefined reference to `nc_inq_dimlen'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: .libs/NCZhdf5filters.o:NCZhdf5filters:(.text+0x245a): undefined reference to `nc_inq_var_chunking'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: .libs/NCZhdf5filters.o:NCZhdf5filters:(.text+0x24ee): undefined reference to `nc_inq_var_endian'
collect2.exe: error: ld returned 1 exit status
make[3]: *** [Makefile:872: lib__nczhdf5filters.la] Error 1
make[3]: Leaving directory '/home/Alexander Barth/netcdf-c-2/plugins'
make[2]: *** [Makefile:731: all] Error 2
make[2]: Leaving directory '/home/Alexander Barth/netcdf-c-2/plugins'
make[1]: *** [Makefile:764: all-recursive] Error 1
make[1]: Leaving directory '/home/Alexander Barth/netcdf-c-2'
make: *** [Makefile:609: all] Error 2

These steps worked when compiling NetCDF 4.8.1 on the same machine.

It might be related to the LDFLAGS passed to make, which is also used here: https://github.com/Unidata/netcdf-c/blob/main/.github/workflows/run_tests_win_mingw.yml#L49

Any help would be greatly appreciated!

Maybe this is related: https://github.com/Unidata/netcdf-c/issues/2419

Alexander-Barth avatar Aug 02 '22 07:08 Alexander-Barth

With the 4.6.0 Fortran release out the door, I am pivoting back to this and other issues we're seeing with the 4.9.0 release. I'll see if I can get this figured out and fixed, I want the release cycle for 4.9.1 to be a very short one.

WardF avatar Aug 02 '22 20:08 WardF

Would it be possible to enable plugins in the MinGW CI tests? And possibly also byte range support?

https://github.com/Unidata/netcdf-c/blob/main/.github/workflows/run_tests_win_mingw.yml#L38

Alexander-Barth avatar Aug 18 '22 09:08 Alexander-Barth

I don't recall why they are disabled to begin with, so let's start by taking a look at what happens if we turn them on.

WardF avatar Aug 18 '22 21:08 WardF

@Alexander-Barth I'm curious, do you run into issues when trying to enable plugins or byterange? I am struggling to get things working, even just with the byterange, in a fresh MSYS2/MinGW64 environment. Starting with byterange, I've been able to eventually get things to compile using pkg-config libcurl --libs and pkg-config libcurl --cflags, but I then observe really odd crashes when I try to use any of the resultant executables. I confess this isn't my usual test/work environment, and if I am making a mistake that's easy to fix, I'd be glad to know about it. I'm able to replicate what's in the MinGW GitHub actions workflow script successfully, no problem.

WardF avatar Aug 19 '22 21:08 WardF

I have plugins building with Autotools here, but hadn't tried byterange. I'm waiting on test results to see what happens. (EDIT: enabling byterange and DAP on MinGW autotools build passes)

I think the big thing with MinGW plugins is that LDADD only works for PROGRAMS targets, not LTLIBRARIES targets; you need to add libnetcdf.la to each program's _LIBADD variable (programs use LDADD, libraries use LIBADD)

DWesl avatar Aug 20 '22 16:08 DWesl