r-spatial / lwgeom

bindings to the liblwgeom library
https://r-spatial.github.io/lwgeom/
58 stars 23 forks source link

can't link {lwgeom} to PROJ 7.2.0 when installing from source #64

Closed mikoontz closed 3 years ago

mikoontz commented 3 years ago

Hello,

I'm trying to do some spatial transformations directly using PROJ in the {stars} package which, as far as I understand, uses {lwgeom} under the hood for the st_transform_proj() function. I'm getting an error, and I suspect it has to do with the incorrect version of PROJ being used. Sure enough, when I load {lwgeom} directly, I get a warning that both the GEOS and PROJ versions differ between {sf} and {lwgeom}:

> library(lwgeom)
Linking to liblwgeom 3.0.0beta1 r16016, GEOS 3.7.2, PROJ 5.2.0
Warning messages:
1: In fun(libname, pkgname) :
  GEOS versions differ: lwgeom has 3.7.2 sf has 3.8.1
2: In fun(libname, pkgname) :
  PROJ versions differ: lwgeom has 5.2.0 sf has 7.2.0

I was trying to install {lwgeom} from source in order to link to the latest installed versions of PROJ and GEOS (which I installed using Homebrew). I get an error that "libproj is not found in the standard location":

> install.packages("lwgeom", type = "source")
trying URL 'https://cran.rstudio.com/src/contrib/lwgeom_0.2-5.tar.gz'
Content type 'application/x-gzip' length 501653 bytes (489 KB)
==================================================
downloaded 489 KB

* installing *source* package ‘lwgeom’ ...
** package ‘lwgeom’ successfully unpacked and MD5 sums checked
** using staged installation
configure: CC: clang
configure: CXX: clang++ -std=gnu++11
configure: pkg-config proj exists, will use it
configure: using proj.h.
configure: PROJ: 7.2.0
checking PROJ: checking whether PROJ and sqlite3 are available for linking:... no
configure: error: libproj not found in standard or given locations.

However, when I install {sf} from source in order to link to the latest versions of GDAL, PROJ, and GEOS, I am able to do so successfully and make it past the same check in the install process that caused a problem when installing {lwgeom}.

Here's the output when (successfully) installing {sf} from source:

> install.packages("sf", type = "source")
trying URL 'https://cran.rstudio.com/src/contrib/sf_0.9-6.tar.gz'
Content type 'application/x-gzip' length 4160758 bytes (4.0 MB)
==================================================
downloaded 4.0 MB

* installing *source* package ‘sf’ ...
** package ‘sf’ successfully unpacked and MD5 sums checked
** using staged installation
configure: CC: clang
configure: CXX: clang++ -std=gnu++11
checking for gdal-config... /usr/local/bin/gdal-config
checking gdal-config usability... yes
configure: GDAL: 3.2.0
checking GDAL version >= 2.0.1... yes
checking for gcc... clang
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 we are using the GNU C compiler... yes
checking whether clang accepts -g... yes
checking for clang option to accept ISO C89... none needed
checking how to run the C preprocessor... clang -E
checking for grep that handles long lines and -e... /usr/bin/grep
checking for egrep... /usr/bin/grep -E
checking for ANSI C header files... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking gdal.h usability... yes
checking gdal.h presence... yes
checking for gdal.h... yes
checking GDAL: linking with --libs only... yes
checking GDAL: /usr/local/Cellar/gdal/3.2.0/share/gdal/pcs.csv readable... no
checking GDAL: checking whether PROJ is available for linking:... yes
checking GDAL: checking whether PROJ is available fur running:... yes
configure: GDAL: 3.2.0
configure: pkg-config proj exists, will use it
configure: using proj.h.
configure: PROJ: 7.2.0
checking PROJ: checking whether PROJ and sqlite3 are available for linking:... yes
checking for geos-config... /usr/local/bin/geos-config

Here is my sessionInfo():

> sessionInfo()
R version 3.6.3 (2020-02-29)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS Catalina 10.15.7

Matrix products: default
BLAS:   /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.6/Resources/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

loaded via a namespace (and not attached):
[1] compiler_3.6.3 tools_3.6.3   

Any thoughts as to why {sf} would install properly from source, but not {lwgeom}?

mikoontz commented 3 years ago

Just noticed this PR (https://github.com/r-spatial/lwgeom/pull/62) so I will try that!

edit: that PR didn't solve my problem.

Note I also tried installing using extra configure.args= as suggested during the install for {sf} (https://r-spatial.github.io/sf/index.html#macos) which did not fix the problem:

install.packages("sf", configure.args = "--with-proj-lib=/usr/local/lib/", type = "source)

jcarbaut commented 3 years ago

Not sure it's exactly the same problem, but I had a similar issue ("checking PROJ: checking whether PROJ and sqlite3 are available for linking:... no"), that was solved when I made the PKG_CONFIG_PATH environment variable point to the directory that contains proj.pc, for my custom installation of PROJ.

jeroen commented 3 years ago

Same problem on MacOS, configure does not try pkg-config --libs --static when trying to link to proj:

* installing *source* package ‘lwgeom’ ...
** using staged installation
configure: CC: clang
configure: CXX: clang++ -std=gnu++11
configure: pkg-config proj exists, will use it
configure: using proj.h.
configure: PROJ: 7.2.1
checking PROJ: checking whether PROJ and sqlite3 are available for linking:... no
configure: error: libproj not found in standard or given locations.
ERROR: configuration failed for package ‘lwgeom’

It fails because proj7 now requires linking to sqlite, tiff and curl:

# pkg-config --libs --static proj
-L/Users/jeroen/Desktop/gdal-3.2.0-catalina/lib/pkgconfig/../../lib -lproj -lsqlite3 -ltiff -lcurl

I think the solution is to modify the configure script and replace -lproj -lsqlite3 with the output of pkg-config.

sebastien-prudhomme commented 3 years ago

Hi @edzer, as it seems this patch is fixing this issue, can you release a new version of lwgeom?

edzer commented 3 years ago

I'd like to but quite a bit more than that is needed for a release; see e.g. https://cran.r-project.org/web/checks/check_results_lwgeom.html . Help welcome, my priorities are somewhere else.

edzer commented 3 years ago

lwgeom 0.2-6 is now on CRAN, thanks to @jeroen !

edzer commented 3 years ago

So, --static causes havoc on platforms where static libraries are not installed by default (several linux distros). @jeroen is this line sufficient to check for MacOS platforms, and suitable to be added before using --static?

jeroen commented 3 years ago

Yes that sounds good.