Opened 5 years ago

Closed 5 years ago

#57733 closed defect (fixed)

netcdf: Ports linking with netcdf also link with hdf5—overlinking?

Reported by: ryandesign (Ryan Carsten Schmidt) Owned by: tenomoto (Takeshi Enomoto)
Priority: Normal Milestone:
Component: ports Version:
Keywords: Cc: Dave-Allured (Dave Allured)
Port: netcdf

Description

When netcdf +netcdf4 is installed, the nccopy, ncdump, ncgen, and ncgen3 programs and the libnetcdf library are linked with libhdf5 and libhdf5_hl (and libz and libcurl), but also:

$ pkg-config netcdf --libs
-L/opt/local/lib -lnetcdf -lhdf5_hl -lhdf5 -lz -ldl -lm -lcurl
$ nc-config --libs
-L/opt/local/lib -lnetcdf -lhdf5_hl -lhdf5 -lz -ldl -lm -lcurl

This means anything that uses one of the above commands to determine what libraries to link to for netcdf will be told that it must link not only with libnetcdf but also with libhdf5 and libhdf5_hl and libz and libcurl. I suspect this is overlinking and that netcdf should not be doing that.

Particularly in the case of libhdf5, this causes problems whenever hdf5 is updated, since it invariably comes with a new major library version number, which means everything linking with it must be rebuilt by having its revision increased. It's easy to identify which ports declare an explicit dependency on the hdf5 port and revbump those, but it is not expected that one would also have to seek out the ports that link with netcdf and revbump them, but that is what we currently have to do; see e.g. https://github.com/macports/macports-ports/pull/3137.

Change History (6)

comment:1 Changed 5 years ago by Dave-Allured (Dave Allured)

For static linking, I think you need to name all those libraries. For dynamic linking, you are right, this is overlinking. From Netcdf install docs:

https://www.unidata.ucar.edu/software/netcdf/docs/getting_and_building_netcdf.html#linking

"For shared builds, only -L${NCDIR}/lib -lnetcdf is needed.
All other libraries will be found automatically."

I am not familiar with pkg-config. In scenarios like this, single library with many dependencies under the hood, what is best practice for use or non-use of pkg-config or nc-config in package make files, and in the port file? I would imagine there is already a standard solution for this.

Use of nc-config and pkg-config is currently being discussed here. Feel free to ask about application to Macports:

https://github.com/Unidata/netcdf-c/issues/1257

comment:2 Changed 5 years ago by Dave-Allured (Dave Allured)

Cc: Dave-Allured added

comment:3 Changed 5 years ago by tenomoto (Takeshi Enomoto)

I summarized the discussion here in the issue 1257. See what the upstream developers answer.

comment:4 Changed 5 years ago by Dave-Allured (Dave Allured)

This problem is now fixed upstream in netcdf-c for pkg-config only. On the next portfile update for new netcdf release 4.6.3, you can use this for dynamic (shared) linking:

$ pkg-config netcdf --libs

And for static builds, add the --static option:

$ pkg-config netcdf --libs --static

See pkg-config docs. This guide to pkg-config is helpful: https://people.freedesktop.org/~dbn/pkg-config-guide.html

comment:5 Changed 5 years ago by Dave-Allured (Dave Allured)

Netcdf update is requested in #58212.

comment:6 Changed 5 years ago by tenomoto (Takeshi Enomoto)

Resolution: fixed
Status: assignedclosed

In 379ff8de4f759f28290a273ef284119b0c40b68c/macports-ports (master):

netcdf: update to 4.4.3 and associated rev-bumps

Closes: #58212
Closes: #57733

Note: See TracTickets for help on using tickets.