mjwoods / RNetCDF

Read and write netcdf format in R
Other
24 stars 9 forks source link

RNetCDF installation fails with Homebrew installation of netcdf #146

Open kevinushey opened 1 month ago

kevinushey commented 1 month ago

This was originally seen with https://github.com/rstudio/renv/issues/2009, but I can reproduce when attempting to install the package from sources on macOS. For example:

> options(repos = c(CRAN = "https://cran.rstudio.com")); install.packages("RNetCDF", type = "source")
Installing package into ‘/Users/kevin/Library/R/arm64/4.4/library’
(as ‘lib’ is unspecified)
trying URL 'https://cran.rstudio.com/src/contrib/RNetCDF_2.9-2.tar.gz'
Content type 'application/x-gzip' length 160580 bytes (156 KB)
==================================================
downloaded 156 KB

* installing *source* package ‘RNetCDF’ ...
** package ‘RNetCDF’ successfully unpacked and MD5 sums checked
** using staged installation
configure: Find compiler/linker variables from environment:
checking CFLAGS... -falign-functions=64 -Wall -g -O2
checking CPPFLAGS... -I/opt/R/arm64/include -DSTRICT_R_HEADERS=1 -Wimplicit-fallthrough -Wall -pedantic
checking LDFLAGS... -L/opt/R/arm64/lib
checking LIBS...
configure: Select C compiler:
checking C compiler from --with-mpicc...
checking C compiler from R... clang -arch arm64
configure: Find compiler/linker variables from R:
checking R_CFLAGS... -falign-functions=64 -Wall -g -O2
checking R_CPPFLAGS... -I/opt/R/arm64/include -DSTRICT_R_HEADERS=1 -Wimplicit-fallthrough -Wall -pedantic
checking R_LDFLAGS... -L/opt/R/arm64/lib
checking for gcc... clang -arch arm64
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether the compiler supports GNU C... yes
checking whether clang -arch arm64 accepts -g... yes
checking for clang -arch arm64 option to enable C11 features... none needed
checking for clang -arch arm64 options needed to detect all undeclared functions... none needed
checking for stdio.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for strings.h... yes
checking for sys/stat.h... yes
checking for sys/types.h... yes
checking for unistd.h... yes
checking whether _WIN32 is declared... no
checking whether __APPLE__ is declared... yes
configure: Operating system is macOS
checking for nc-config... yes
configure: Check compiler/linker variables from nc-config:
checking NC_CC... clang
checking NC_CC matches selected C compiler... no ... specify --with-mpicc if needed
checking nc-config --cflags... -I/opt/homebrew/Cellar/netcdf/4.9.2_2/include
checking nc-config allows --static option... yes
checking nc-config --libs --static... -L/opt/homebrew/Cellar/netcdf/4.9.2_2/lib -lnetcdf -lhdf5_hl-shared -lhdf5-shared -lm -lz -lzstd -lbz2 -lcurl -lxml2
configure: Check compiler type sizes and language features
checking size of int... 0
checking size of long long... 0
checking size of size_t... 0
checking for C/C++ restrict keyword... __restrict__
configure: Check NetCDF features:
checking for netcdf.h... yes
checking for library containing nc_open... no
configure: error: netcdf library was not linked - defining LDFLAGS may help
ERROR: configuration failed for package ‘RNetCDF’

The problem here is that nc-config appears to be giving bogus libraries Note the line:

checking nc-config --libs --static... -L/opt/homebrew/Cellar/netcdf/4.9.2_2/lib -lnetcdf -lhdf5_hl-shared -lhdf5-shared -lm -lz -lzstd -lbz2 -lcurl -lxml2

This leads to this failure:

checking for library containing nc_open... no

Even though static libraries are being requested, HDF5 "shared" libraries appear to be requested in the invocation, and those libraries do not exist with that name in a Homebrew hdf5 installation. They also shouldn't be needed for this particular test, if I understand correctly?

Here's the lines of interest in config.log:

configure:5694: checking for library containing nc_open
configure:5724: clang -arch arm64 -o conftest -I/opt/homebrew/Cellar/netcdf/4.9.2_2/include -falign-functions=64 -Wall -g -O2 -falign-functions=64 -Wall -g -O2 -I/opt/R/arm64/include -DSTRICT_R_HEADERS=1 -Wimplicit-fallthrough -Wall -pedantic -I/opt/R/arm64/include -DSTRICT_R_HEADERS=1 -Wimplicit-fallthrough -Wall -pedantic -L/opt/R/arm64/lib -L/opt/R/arm64/lib conftest.c -L/opt/homebrew/Cellar/netcdf/4.9.2_2/lib -lnetcdf -lhdf5_hl-shared -lhdf5-shared -lm -lz -lzstd -lbz2 -lcurl -lxml2  >&5
conftest.c:30:14: warning: a function declaration without a prototype is deprecated in all versions of C [-Wstrict-prototypes]
   30 | char nc_open ();
      |              ^
      |               void
1 warning generated.
ld: library 'hdf5_hl-shared' not found
clang: error: linker command failed with exit code 1 (use -v to see invocation)

For reference, with hdf5:

$ ll /opt/homebrew/opt/hdf5/lib/
total 29608
drwxr-xr-x  41 kevin  admin   1.3K Oct  1 18:24 ./
drwxr-xr-x  11 kevin  admin   352B Oct  1 18:24 ../
drwxr-xr-x   3 kevin  admin    96B May 22 11:43 cmake/
-r--r--r--   1 kevin  admin   3.4M Oct  1 18:24 libhdf5.310.4.0.dylib
lrwxr-xr-x   1 kevin  admin    21B May 22 11:43 libhdf5.310.dylib@ -> libhdf5.310.4.0.dylib
-r--r--r--   1 kevin  admin   7.6M May 22 11:43 libhdf5.a
lrwxr-xr-x   1 kevin  admin    17B May 22 11:43 libhdf5.dylib@ -> libhdf5.310.dylib
-r--r--r--   1 kevin  admin   3.9K Oct  1 18:24 libhdf5.settings
-rw-r--r--   1 kevin  admin   426K Oct  1 18:24 libhdf5_cpp.310.0.4.dylib
lrwxr-xr-x   1 kevin  admin    25B May 22 11:43 libhdf5_cpp.310.dylib@ -> libhdf5_cpp.310.0.4.dylib
-r--r--r--   1 kevin  admin   734K May 22 11:43 libhdf5_cpp.a
lrwxr-xr-x   1 kevin  admin    21B May 22 11:43 libhdf5_cpp.dylib@ -> libhdf5_cpp.310.dylib
-r--r--r--   1 kevin  admin   139K Oct  1 18:24 libhdf5_f90cstub.310.3.0.dylib
lrwxr-xr-x   1 kevin  admin    30B May 22 11:43 libhdf5_f90cstub.310.dylib@ -> libhdf5_f90cstub.310.3.0.dylib
-r--r--r--   1 kevin  admin   101K May 22 11:43 libhdf5_f90cstub.a
lrwxr-xr-x   1 kevin  admin    26B May 22 11:43 libhdf5_f90cstub.dylib@ -> libhdf5_f90cstub.310.dylib
-r--r--r--   1 kevin  admin   358K Oct  1 18:24 libhdf5_fortran.310.3.0.dylib
lrwxr-xr-x   1 kevin  admin    29B May 22 11:43 libhdf5_fortran.310.dylib@ -> libhdf5_fortran.310.3.0.dylib
-r--r--r--   1 kevin  admin   388K May 22 11:43 libhdf5_fortran.a
lrwxr-xr-x   1 kevin  admin    25B May 22 11:43 libhdf5_fortran.dylib@ -> libhdf5_fortran.310.dylib
-rw-r--r--   1 kevin  admin   152K Oct  1 18:24 libhdf5_hl.310.0.4.dylib
lrwxr-xr-x   1 kevin  admin    24B May 22 11:43 libhdf5_hl.310.dylib@ -> libhdf5_hl.310.0.4.dylib
-r--r--r--   1 kevin  admin   148K May 22 11:43 libhdf5_hl.a
lrwxr-xr-x   1 kevin  admin    20B May 22 11:43 libhdf5_hl.dylib@ -> libhdf5_hl.310.dylib
-r--r--r--   1 kevin  admin    55K Oct  1 18:24 libhdf5_hl_cpp.310.0.4.dylib
lrwxr-xr-x   1 kevin  admin    28B May 22 11:43 libhdf5_hl_cpp.310.dylib@ -> libhdf5_hl_cpp.310.0.4.dylib
-r--r--r--   1 kevin  admin    10K May 22 11:43 libhdf5_hl_cpp.a
lrwxr-xr-x   1 kevin  admin    24B May 22 11:43 libhdf5_hl_cpp.dylib@ -> libhdf5_hl_cpp.310.dylib
-rw-r--r--   1 kevin  admin    74K Oct  1 18:24 libhdf5_hl_f90cstub.310.0.4.dylib
lrwxr-xr-x   1 kevin  admin    33B May 22 11:43 libhdf5_hl_f90cstub.310.dylib@ -> libhdf5_hl_f90cstub.310.0.4.dylib
-r--r--r--   1 kevin  admin    25K May 22 11:43 libhdf5_hl_f90cstub.a
lrwxr-xr-x   1 kevin  admin    29B May 22 11:43 libhdf5_hl_f90cstub.dylib@ -> libhdf5_hl_f90cstub.310.dylib
-rw-r--r--   1 kevin  admin   150K Oct  1 18:24 libhdf5_hl_fortran.310.0.4.dylib
lrwxr-xr-x   1 kevin  admin    32B May 22 11:43 libhdf5_hl_fortran.310.dylib@ -> libhdf5_hl_fortran.310.0.4.dylib
-r--r--r--   1 kevin  admin   131K May 22 11:43 libhdf5_hl_fortran.a
lrwxr-xr-x   1 kevin  admin    28B May 22 11:43 libhdf5_hl_fortran.dylib@ -> libhdf5_hl_fortran.310.dylib
-rw-r--r--   1 kevin  admin   272K Oct  1 18:24 libhdf5_tools.310.0.4.dylib
lrwxr-xr-x   1 kevin  admin    27B May 22 11:43 libhdf5_tools.310.dylib@ -> libhdf5_tools.310.0.4.dylib
-r--r--r--   1 kevin  admin   417K May 22 11:43 libhdf5_tools.a
lrwxr-xr-x   1 kevin  admin    23B May 22 11:43 libhdf5_tools.dylib@ -> libhdf5_tools.310.dylib
drwxr-xr-x   8 kevin  admin   256B Oct  1 18:24 pkgconfig/
mjwoods commented 1 month ago

Hi @kevinushey , if nc-config is reporting bogus libraries on Homebrew, it may be important to report this issue to the Homebrew project.

As a workaround, please try the --with-nc-config-static=no configure option when installing RNetCDF. For example:

install.packages("RNetCDF", type="source", configure.args="--with-nc-config-static=no")
kevinushey commented 1 month ago

Thanks! That does indeed resolve the issue; this at least gives me something to refer to if the issue comes up again on the renv side.