Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

error Rlog1p #330

Closed
wants to merge 1 commit into from
Closed

error Rlog1p #330

wants to merge 1 commit into from

Conversation

yfyang86
Copy link

On

R version 4.0.3 (2020-10-10)
Platform: aarch64-apple-darwin20.0.0 (64-bit)
Apple clang version 12.0.0 (clang-1200.0.32.29)
Target: arm64-apple-darwin20.3.0

The original source code fails with the message:

../inst/include/armadillo_bits/eop_aux.hpp:98:115: error: no member named 'Rlog1p' in namespace 'std'; did you mean simply 'Rlog1p'?

which shows a conflict of std::log1p with #define log1p Rlog1p in Rmath.h

On

```
R version 4.0.3 (2020-10-10)
Platform: aarch64-apple-darwin20.0.0 (64-bit)
Apple clang version 12.0.0 (clang-1200.0.32.29)
Target: arm64-apple-darwin20.3.0
```

The original source code fails with the message:

```
../inst/include/armadillo_bits/eop_aux.hpp:98:115: error: no member named 'Rlog1p' in namespace 'std'; did you mean simply 'Rlog1p'?
```

which show a conflict of `std::log1p` with `#define log1p Rlog1p` in `Rmath.h`
@eddelbuettel
Copy link
Member

eddelbuettel commented Mar 16, 2021

Can you provide a short code example that triggers it?

Can you state which RcppArmadillo version you used? Can you maybe try the one in the Rcpp drat repo too (which is based on Armadill 10.3-rc*)?

Also, we may want to try to deal with this (if it all) at the #define level before sourcing any Armadillo files.

@@ -22,6 +22,8 @@
//! use of the SFINAE approach to work around compiler limitations
//! http://en.wikipedia.org/wiki/SFINAE

#undef log1p

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We almost surely do not want to unconditionally undefine something in the upstream sources.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one is a workaround. I will make another PR if I succeed in changing the configure file instead of modifying the upstream armadillo code.

Here is my environment information:

> sessionInfo()
R version 4.0.3 (2020-10-10)
Platform: aarch64-apple-darwin20.0.0 (64-bit)
Running under: macOS  11.2

Matrix products: default
BLAS:   /Users/xxx/miniforge3/envs/py38/lib/R/lib/libRblas.dylib
LAPACK: /Users/xxx/miniforge3/envs/py38/lib/R/lib/libRlapack.dylib

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

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

loaded via a namespace (and not attached):
[1] compiler_4.0.3 tools_4.0.3  

with (on Mac M1):

Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/4.2.1
Apple clang version 12.0.0 (clang-1200.0.32.29)
Target: arm64-apple-darwin20.3.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

and

> packageVersion("Rcpp")
[1] ‘1.0.6’

I use the the latest CRAN/Github master version to install RcppArmadillo , then it reports an error

arm64-apple-darwin20.0.0-clang++ -std=gnu++11 -I"/Users/yifanyang/miniforge3/envs/py38/lib/R/include" -DNDEBUG  -I'/Users/yifanyang/miniforge3/envs/py38/lib/R/library/Rcpp/include' -D_FORTIFY_SOURCE=2 -isystem /Users/yifanyang/miniforge3/envs/py38/include -mmacosx-version-min=11.0 -I/Users/yifanyang/miniforge3/envs/py38/include  -I../inst/include  -fPIC  -ftree-vectorize -fPIC -fPIE -fstack-protector-strong -O2 -pipe -stdlib=libc++ -fvisibility-inlines-hidden  -fmessage-length=0 -isystem /Users/yifanyang/miniforge3/envs/py38/include -fdebug-prefix-map=/Users/runner/miniforge3/conda-bld/r-base-split_1615277992527/work=/usr/local/src/conda/r-base-4.0.3 -fdebug-prefix-map=/Users/yifanyang/miniforge3/envs/py38=/usr/local/src/conda-prefix  -c RcppArmadillo.cpp -o RcppArmadillo.o
In file included from RcppArmadillo.cpp:21:
In file included from ../inst/include/RcppArmadillo.h:31:
In file included from ../inst/include/RcppArmadilloForward.h:49:
In file included from ../inst/include/armadillo:374:
../inst/include/armadillo_bits/eop_aux.hpp:97:124: error: no member named 'Rlog1p' in namespace 'std'; did you mean 'log1p'?
  template<typename eT> arma_inline static typename   arma_integral_only<eT>::result log1p (const eT  x) { return eT( std::log1p(double(x)) ); }
                                                                                                                      ~~~~~^~~~~
                                                                                                                           log1p
/Users/yifanyang/miniforge3/envs/py38/lib/R/include/Rmath.h:75:15: note: expanded from macro 'log1p'
#define log1p Rlog1p
              ^
/Users/yifanyang/miniforge3/envs/py38/bin/../include/c++/v1/cmath:435:9: note: 'log1p' declared here
using ::log1p;
        ^
In file included from RcppArmadillo.cpp:21:
In file included from ../inst/include/RcppArmadillo.h:31:
In file included from ../inst/include/RcppArmadilloForward.h:49:
In file included from ../inst/include/armadillo:374:
../inst/include/armadillo_bits/eop_aux.hpp:98:115: error: no member named 'Rlog1p' in namespace 'std'; did you mean simply 'Rlog1p'?
  template<typename eT> arma_inline static typename       arma_real_only<eT>::result log1p (const eT  x) { return std::log1p(x);               }
                                                                                                                  ^~~~~~~~~~
                                                                                                                  Rlog1p
../inst/include/armadillo_bits/eop_aux.hpp:99:86: note: 'Rlog1p' declared here
  template<typename eT> arma_inline static typename         arma_cx_only<eT>::result log1p (const eT& x) { arma_ignore(x); return eT(0);       }
                                                                                     ^
/Users/yifanyang/miniforge3/envs/py38/lib/R/include/Rmath.h:75:15: note: expanded from macro 'log1p'
#define log1p Rlog1p
              ^
In file included from RcppArmadillo.cpp:21:
In file included from ../inst/include/RcppArmadillo.h:31:
In file included from ../inst/include/RcppArmadilloForward.h:49:
In file included from ../inst/include/armadillo:433:
../inst/include/armadillo_bits/fn_misc.hpp:170:21: error: no member named 'Rlog1p' in namespace 'std'; did you mean simply 'Rlog1p'?
    return (log_a + std::log1p(std::exp(negdelta)));
                    ^~~~~~~~~~
                    Rlog1p
/Users/yifanyang/miniforge3/envs/py38/lib/R/include/Rmath.h:74:9: note: 'Rlog1p' declared here
double  Rlog1p(double);
        ^
3 errors generated.
make: *** [/Users/yifanyang/miniforge3/envs/py38/lib/R/etc/Makeconf:181: RcppArmadillo.o] Error 1
ERROR: compilation failed for package ‘RcppArmadillo’

@eddelbuettel
Copy link
Member

You can also try to define #undef ARMA_HAVE_LOG1P before your includes. Many options, let's get a reproducible example first as this may be compiler / platform dependent.

@eddelbuettel
Copy link
Member

I am sure we can sort this out. Don't run off modifying configure, please, or waste time in other ways. Let's just analyse a little more.

Can you please provide a short file with either Rcpp::cppFunction() in a one-or-two-liner or for Rcpp::sourceCpp() to trigger this? RcppArmadillo has well over 800 reverse depends on CRAN and is used in a number of ways, and this has not come up yet. It could be as simple as re-ordering header files too. But we need to know more before we get into action.

(And that is precisely why we say here over at Rcpp to first file an issue to discuss matters before going off on pull requests which may just get rejected.)

@yfyang86
Copy link
Author

yfyang86 commented Mar 16, 2021

Here is an working example, with log1p in C++11 cmath ref:

> code = ' void simple_test(){std::cout << "log1p(0) = " << std::log1p(0) << std::endl;}'
> cppFunction(plugins=c("cpp11"), code)
file8a824422791b.cpp:7:51: error: no member named 'Rlog1p' in namespace 'std'; did you mean simply 'Rlog1p'?
 void simple_test(){std::cout << "log1p(0) = " << std::log1p(0) << std::endl;}
                                                  ^~~~~~~~~~
                                                  Rlog1p
/Users/yifanyang/miniforge3/envs/py38/lib/R/include/Rmath.h:74:9: note: 'Rlog1p' declared here
double  Rlog1p(double);
        ^
1 error generated.

Update: I delete the misleading void error.

@eddelbuettel
Copy link
Member

Sorry, don't see it:

> Rcpp::cppFunction("double issue330(double x) { return std::log1p(x); }")
> issue330(1.234)
[1] 0.803794
> 

Ubuntu 20.10, g++ 10.2. Also passes with clang++-11.

To me, you have not yet provided a reproducible example.

@eddelbuettel
Copy link
Member

I see miniforge in your output; maybe you set yourself up for an interaction with other headers. I would not know. CRAN also does not use conda.

@eddelbuettel
Copy link
Member

I can also merrily call ::log1p() as the Rcpp sources do too:

> Rcpp::cppFunction("double issue330r(double x) { return ::log1p(x); }")
> issue330r(1.234)
[1] 0.803794
> 

So maybe for your Conda use you need to #undef HAVE_LOG1P ? Maybe you try and experiment in a simpler "clean room" setup via Docker. I still see no issue in our sources.

@yfyang86
Copy link
Author

I see miniforge in your output; maybe you set yourself up for an interaction with other headers. I would not know. CRAN also does not use conda.

May that's the reason. I tried on other platforms and got no error. I will try to make a clean install (of R) tomorrow and figure out why. I think it might be the way the compiler expands the macro causes the issue. Hence maybe this one is only an issue on Mac M1 miniforge3's R version (the tool chain on new Mac is a disaster for developers). I will close this one and report in other thread if there is anything interesting there.

@yfyang86 yfyang86 closed this Mar 16, 2021
@eddelbuettel
Copy link
Member

We should still try to get to it (not here but maybe as a Conda bug report) as it seems that a define gets in the way.

@kevinushey
Copy link
Contributor

The relevant part of Rmath.h:

https://github.com/wch/r-source/blob/75a1b9791926ba24e18b9f2f58634e8233898216/src/include/Rmath.h0.in#L72-L76

That is,

#if !defined(HAVE_WORKING_LOG1P)
/* remap to avoid problems with getting the right entry point */
double  Rlog1p(double);
#define log1p Rlog1p
#endif

So the issue is most likely that your installed copy of R believes (correctly or incorrectly?) that your platform doesn't have log1p defined, and so R is trying to stuff its own definition in.

Does compilation succeed if you set -DHAVE_WORKING_LOG1P?

@yfyang86
Copy link
Author

Does compilation succeed if you set -DHAVE_WORKING_LOG1P?

I also traced #if !defined(HAVE_WORKING_LOG1P) (version4.0.x) in Rmath.h, and will test why configure file (to be precisely, the conda R environment, not the configure file) fails to detect it.

Manually change the PKG_CXXFLAGS flag in RcppArmadillo/src/Makevars.in into:

PKG_CXXFLAGS = -I../inst/include @OPENMP_FLAG@ -DHAVE_WORKING_LOG1P 

could compile the package successfully. That's why

I will try to make a clean install (of R) tomorrow and figure out why.

R-4.0 is installed through a standard native ARM64 conda. For anyone with the same issue, I record the conda environment here:

            shell level : 2
       user config file : /Users/yifanyang/.condarc
 populated config files : /Users/yifanyang/miniforge3/.condarc
          conda version : 4.9.2
    conda-build version : not installed
         python version : 3.9.2.final.0
       virtual packages : __osx=11.2=0
                          __unix=0=0
                          __archspec=1=arm64
       base environment : /Users/yifanyang/miniforge3  (writable)
           channel URLs : https://conda.anaconda.org/conda-forge/osx-arm64
                          https://conda.anaconda.org/conda-forge/noarch
          package cache : /Users/yifanyang/miniforge3/pkgs
                          /Users/yifanyang/.conda/pkgs
       envs directories : /Users/yifanyang/miniforge3/envs
                          /Users/yifanyang/.conda/envs
               platform : osx-arm64
             user-agent : conda/4.9.2 requests/2.25.1 CPython/3.9.2 Darwin/20.3.0 OSX/11.2
                UID:GID : 501:20
             netrc file : None
           offline mode : False

@eddelbuettel
Copy link
Member

eddelbuettel commented Mar 16, 2021

Manually change the PKG_CXXFLAGS flag in RcppArmadillo/src/Makevars.in into:

You probably want to add it to CXXFLAGS (or CPPFLAGS) in either your own ~/.R/Makevars or your installation-wide one in R's etc/ directory. That's what I do for, say, some Boost flags and like. Be mindful that you may need it several times for the different C++ standards: 11, 14, 17, ...

@isuruf
Copy link

isuruf commented Mar 17, 2021

So the issue is most likely that your installed copy of R believes (correctly or incorrectly?) that your platform doesn't have log1p defined, and so R is trying to stuff its own definition in.

This is an issue with conda-forge's R package. Please open an issue in https://github.com/conda-forge/r-base-feedstock and we'll get it fixed ASAP.

@yfyang86
Copy link
Author

Update Here on conda-forge. I recompiled R from the source, and this issue is solved.

@eddelbuettel
Copy link
Member

Good to know you're set; would probably still be good to help the conda folks get the package right.

@Sue9104
Copy link

Sue9104 commented Mar 28, 2023

Binary packages are available.
install.packages("RcppArmadillo", type="mac.binary") works for me.

@mmtmr
Copy link

mmtmr commented Apr 9, 2023

Binary packages are available.
install.packages("RcppArmadillo", type="mac.binary") works for me.

This is the only solution that works for me, thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants