[R-SIG-Mac] Problem installing ncdf4, in Homebrew R

Prof Brian Ripley ripley at stats.ox.ac.uk
Wed Nov 20 22:25:20 CET 2013

On 20/11/2013 20:49, Tobey Carman wrote:
> Hi -
> I am not sure if this is the right place for this question. I am fairly new
> to R and still figuring out how to best manage packages. If this is not the
> best venue for this question, please direct me elsewhere.

It will do, but 'the homebrew version of R' is not anything official and 
you would probably do better to ask on R-devel since you are treating OS 
X as another Unix-alike.

The package has a broken configure, and has been reported to the 
so-called maintainer long ago.

You omitted the line with the error.  On my (native OS X) system you can 
see the log at 
. Note the link command there:

clang -mtune=native -dynamiclib -Wl,-headerpad_max_install_names 
-undefined dynamic_lookup -single_module -multiply_defined suppress 
-L/usr/local/lib -o ncdf4.so ncdf.o ncdf2.o ncdf3.o src_ncdf4.o 
-Wl,-rpath, -L/usr/local/lib -lnetcdf -lhdf5_hl -lhdf5 -lm -lz -lcurl 
-L/Users/ripley/R/R-devel/lib -lR -dylib_file 
libRblas.dylib:/Users/ripley/R/R-devel/lib/libRblas.dylib -Wl,-framework 

The use of -Wl,-rpath, is simply wrong and swallows -lnetcdf.  So you 
need to correct it.

One way to do so is to unpack the sources, try to install, copy the 
PKG_LIBS from src/Makevars to src/Makevars.in, correct it and try again.

I have in src/Makevars.in

PKG_LIBS= -L/usr/local/lib -lnetcdf -lhdf5_hl -lhdf5 -lm -lz -lcurl

but your mileage may differ (and probably will if you have a dynamic 

> I am trying to install the ncdf4 R package using:
>> install.packages('ncdf4')
> This command, downloads the package, finds nc-config, appears to collect
> all the correct settings, and appears to compile ncdf4 with no errors. But
> after compiling, and running a few tests, the command fails during a test
> to load the just-compiled ncdf4 libraries:
>> install.packages('ncdf4')
> ...
> skipping lots of output for downloading, nc-config, configuring, compiling,
> testing...
> ...
> ** testing if installed package can be loaded
> Error in dyn.load(file, DLLpath = DLLpath, ...) :
>    unable to load shared object
> '/usr/local/Cellar/r/3.0.0/R.framework/Versions/3.0/Resources/library/ncdf4/libs/ncdf4.so':
> dlopen(/usr/local/Cellar/r/3.0.0/R.framework/Versions/3.0/Resources/library/ncdf4/libs/ncdf4.so,
> 6): Symbol not found: _nc_close
>    Referenced from:
> /usr/local/Cellar/r/3.0.0/R.framework/Versions/3.0/Resources/library/ncdf4/libs/ncdf4.so
>    Expected in: flat namespace
>   in
> /usr/local/Cellar/r/3.0.0/R.framework/Versions/3.0/Resources/library/ncdf4/libs/ncdf4.so
> Error: loading failed
> Execution halted
> ERROR: loading failed
> * removing
> ‘/usr/local/Cellar/r/3.0.0/R.framework/Versions/3.0/Resources/library/ncdf4’
> Warning in install.packages :
>    installation of package ‘ncdf4’ had non-zero exit status
> I am on a Mac, 10.8.2. I am using Homebrew to manage my packages. I have
> the main netcdf library,,  that is installed via Homebrew and has
> been working fine in several other applications. Likewise I am using a
> Homebrew version of R.
> I am not sure how to keep trouble shooting this. I can provide more output
> if necessary.
> Thanks,
> Tobey Carman
> Spatial Ecology Lab,
> University of Alaska Fairbanks
> 	[[alternative HTML version deleted]]
> _______________________________________________
> R-SIG-Mac mailing list
> R-SIG-Mac at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-mac

Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

More information about the R-SIG-Mac mailing list