Unidata / netcdf-cxx4

Official GitHub repository for netCDF-C++ libraries and utilities.
Other
124 stars 49 forks source link

Fix the build with -no-undefined. #103

Closed orbea closed 3 years ago

orbea commented 3 years ago

When building netcdf-cxx4 with sblitool (https://dev.midipix.org/cross/slibtool) it fails with many undefined references. This is because the build used -no-undefined which GNU libtool silently ignores while slibtool does not.

  1. -lnetcdf should be in LIBADD and not LDADD. - Build log: netcdf-cxx4.rdlibtool.log
  2. The global LDADD variable is unused and LDADD should be used for linking dependencies for programs, for example: foo_LDADD = bar.la. The global variable is LIBS, but it should just be removed instead since linking against yourself is wrong in this case.
  3. libh5bzip2.la depends on hdf5 and the -lhdf5 linker flag is missing.
    
    rdlibtool --tag=CC --mode=link gcc -g -O2 -module -avoid-version -shared -export-dynamic -no-undefined -o libh5bzip2.la -rpath /usr/local/lib H5Zbzip2.lo blocksort.lo huffman.lo crctable.lo randtable.lo compress.lo decompress.lo bzlib.lo

rdlibtool: lconf: {.name="libtool"}. rdlibtool: fdcwd: {.fdcwd=AT_FDCWD, .realpath="/tmp/netcdf-cxx4/plugins"}. rdlibtool: lconf: fstatat(AT_FDCWD,".",...) = 0 {.st_dev = 45, .st_ino = 324927}. rdlibtool: lconf: openat(AT_FDCWD,"libtool",O_RDONLY,0) = -1 [ENOENT]. rdlibtool: lconf: openat(AT_FDCWD,"../",O_DIRECTORY,0) = 3. rdlibtool: lconf: fstat(3,...) = 0 {.st_dev = 45, .st_ino = 315376}. rdlibtool: lconf: openat(3,"libtool",O_RDONLY,0) = 4. rdlibtool: lconf: found "/tmp/netcdf-cxx4/libtool". rdlibtool: link: ln -s /dev/null .libs/libh5bzip2.a.disabled rdlibtool: link: gcc .libs/H5Zbzip2.o .libs/blocksort.o .libs/huffman.o .libs/crctable.o .libs/randtable.o .libs/compress.o .libs/decompress.o .libs/bzlib.o -g -O2 -shared -fPIC -Wl,--no-undefined -o .libs/libh5bzip2.so -Wl,--export-dynamic /usr/lib/gcc/x86_64-pc-linux-gnu/10.2.0/../../../../x86_64-pc-linux-gnu/bin/ld: .libs/H5Zbzip2.o: in function H5Z_filter_bzip2': /tmp/netcdf-cxx4/plugins/H5Zbzip2.c:204: undefined reference toH5free_memory' /usr/lib/gcc/x86_64-pc-linux-gnu/10.2.0/../../../../x86_64-pc-linux-gnu/bin/ld: /tmp/netcdf-cxx4/plugins/H5Zbzip2.c:212: undefined reference to `H5free_memory' collect2: error: ld returned 1 exit status rdlibtool: exec error upon slbt_exec_link_create_library(), line 1446: (see child process error messages). rdlibtool: < returned to > slbt_exec_link(), line 1868. make[1]: [Makefile:467: libh5bzip2.la] Error 2 make[1]: Leaving directory '/tmp/netcdf-cxx4/plugins' make: [Makefile:542: install-recursive] Error 1

CLAassistant commented 3 years ago

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

orbea commented 3 years ago

Also see this downstream issue. https://bugs.gentoo.org/778200

WardF commented 3 years ago

Thanks!

orbea commented 3 years ago

I updated this PR to correctly use LIBADD instead of LDFLAGS and to remove the incorrect and unused LDADD variable.

WardF commented 3 years ago

Thank you!