AndriSignorell / DescTools

Tools for Descriptive Statistics and Exploratory Data Analysis
http://andrisignorell.github.io/DescTools/
82 stars 18 forks source link

An error when installing DescTools in Linux platform with aux_fct.cpp and potential solution #152

Closed Mashiro-Mirror closed 1 month ago

Mashiro-Mirror commented 2 months ago

When installing DescTools in Linux, the process went wrong with c++: gcc -I"/opt/R/4.2.2/lib64/R/include" -DNDEBUG -I'/opt/R/4.2.2/lib64/R/library/Rcpp/include' -I/usr/local/include -fpic -g -O2 -c ADinf.c -o ADinf.o gcc -I"/opt/R/4.2.2/lib64/R/include" -DNDEBUG -I'/opt/R/4.2.2/lib64/R/library/Rcpp/include' -I/usr/local/include -fpic -g -O2 -c AnDarl.c -o AnDarl.o g++ -std=gnu++17 -I"/opt/R/4.2.2/lib64/R/include" -DNDEBUG -I'/opt/R/4.2.2/lib64/R/library/Rcpp/include' -I/usr/local/include -fpic -g -O2 -c RcppExports.cpp -o RcppExports.o g++ -std=gnu++17 -I"/opt/R/4.2.2/lib64/R/include" -DNDEBUG -I'/opt/R/4.2.2/lib64/R/library/Rcpp/include' -I/usr/local/include -fpic -g -O2 -c aux_fct.cpp -o aux_fct.o aux_fct.cpp: In function ‘Rcpp::List n_pow_sum(Rcpp::NumericVector)’: aux_fct.cpp:205:23: error: ‘reduce’ is not a member of ‘std’ double mean = std::reduce(x.begin(), x.end(), 0.0, std::plus()) / x.size(); ^~ aux_fct.cpp:205:23: note: suggested alternative: ‘replace’ double mean = std::reduce(x.begin(), x.end(), 0.0, std::plus()) / x.size(); ^~ replace

Notice that the version of GCC is adequate to support c++17 (gnu++17) so the problem probably lies in the aux_fct.cpp file. The original line 205 is: double mean = std::reduce(x.begin(), x.end(), 0.0, std::plus()) / x.size(); The std::reduce here is designed to calculate the mean value of the object Rcpp::NumericVector. So I tried to re-write the line and use std::accumulate to replace the original line like the following: double sum = std::accumulate(x.begin(), x.end(), 0.0, std::plus()); double mean = sum / x.size(); After the modification of the source code, the compilation could be successful.

AndriSignorell commented 2 months ago

This is a known issue. It is related to a C++ function that I used because of a significant performance gain, which however is only supported by C++ 17. See also: [(https://github.com/AndriSignorell/DescTools/issues/135 )] [https://github.com/IQSS/dataverse/issues/10452]

Update your tools chain and try again.

AndriSignorell commented 1 month ago

I'll close this as I cannot do anything about it... ;-) Hope this is ok.

Jorges1000 commented 6 days ago

Hi,

I am having the same error and don't see instructions on how to fix it. using C compiler: gcc (Ubuntu 7.5.0-3ubuntu1-18.04) 7.5.0 using Fortran compiler: GNU Fortran (Ubuntu 7.5.0-3ubuntu1-18.04) 7.5.0 using C++ compiler: g++ (Ubuntu 7.5.0-3ubuntu1-18.04) 7.5.0 using C++17

It is related to a C++ function that I used because of a significant performance gain, which however is only supported by C++ 17.

I am using C++ 17

Update your tools chain and try again.

Could you please clarify which tools need updating?

Thanks!