MichaelChirico / r-bugs

A ⚠️read-only⚠️mirror of https://bugs.r-project.org/
20 stars 0 forks source link

[BUGZILLA #15788] Possible omission or incorrect documentation for "R CMD config --ldflags" #5329

Closed MichaelChirico closed 4 years ago

MichaelChirico commented 4 years ago

The RPy2 R-Python bridge will not install on OS X (10.8.5) using Homebrew's Python and its "science" tap installation of R-3.1.0. It is not able to locate the libR shared library.

There are two causes. Firstly, brew builds a framework version of R, but without the ""--enable-R-shlib" flag needed to build a shared library. This is easily fixed with a 1-line patch to the R formula in Homebrew.

However, even with libR built, RPy2 cannot find libR within the framework (although it does find it if I link libR into /usr/local/lib). I filed a bug report for this with RPy2:

https://bitbucket.org/lgautier/rpy2/issue/194/libr-not-found-on-os-x-with-homebrew-r

My diagnosis was that RPy2's setup.py appeared to be relying on "R CMD config --ldflags" to locate libR. The lead developer confirmed this is true; this approach is based on R's own documentation:

$ R CMD config
Usage: R CMD config [options] [VAR]

Get the value of a basic R configure variable VAR which must be among
those listed in the 'Variables' section below, or the header and
library flags necessary for linking against R.

Options:
  -h, --help            print short help message and exit
  -v, --version         print version info and exit
      --cppflags        print pre-processor flags required to compile
            a C/C++ file using R as a library
      --ldflags         print linker flags needed for linking a front-end
                        against the R library
      --no-user-files  ignore customization files under∼/.R
      --no-site-files  ignore site customization files under R_HOME/etc

However, for a framework build, the result of "R CMD config --ldflags" is:

-F/usr/local/Cellar/r/3.1.0/R.framework/.. -framework R -llzma -licucore -lm -liconv

This does not appear to provide the information needed to link against libR when libR is within a framework (at least, RPy2's use of it fails to find libR).

Note that the "--cppflags" option does provide the path to header files within the framework:

-I/usr/local/Cellar/r/3.1.0/R.framework/Resources/include

The RPy2 devs are basing their build process on the R CMD config help documentation. If the documentation is in error (at least for framework builds), acknowledgment and/or a patch will likely lead to the proper fix within RPy2. If there is some other approach that should be used to enable external software to discover how to link against a framework libR, please clarify.

Thanks!


METADATA

MichaelChirico commented 4 years ago

Looking further into this, RPy2 is using the -F path to build the following -L search path for libR:

-L/usr/local/Cellar/r/3.1.0/R.framework/Resources/modules

There are indeed libraries in that path, but not libR; it lives in R.framework/Libraries.

I'm having trouble locating documentation of what path a resource like libR.dylib should have. The clang documentation does not mention a Libraries directory in Darwin frameworks:

http://clang.llvm.org/docs/Modules.html

[search for "Module declaration"]. Any pointers that would help guide the construction of a sound setup.py that would be robust to future changes would be appreciated.


METADATA

MichaelChirico commented 4 years ago

An additional information.

Fink's rpy2 explicitly sets LDFLASGS as -L/sw/Library/Frameworks/R.framework/Versions/3.0/Resources/lib (as well as -undefined dynamic_lookup)


METADATA

MichaelChirico commented 4 years ago

The missing documentation is that installing as a foundation is a non-standard install: that has been added.


METADATA

MichaelChirico commented 4 years ago

If you build R as a framework following the instructions in the manual, you get

-F/Library/Frameworks/R.framework/.. -framework R -llzma -lz -licucore -lm -liconv

as indeed is given by the CRAN binary distribution. And if I link some of the examples in tests/Embedded I get

clang -o Rtest Rtest.o embeddedRCall.o R CMD config --ldflags

which works correctly, e.g.

% R_HOME=R RHOME Rtest --silent [1] 1 2 3 4 5 6 7 8 9 10

So it seems the issue is not using a framework in the documented way. It is not clear for example that Apple compilers/linkers were used.


METADATA