Skip to content

Fixing compile issues on SPARC Solaris

April 3, 2017

Time for a new version of my R package, to fix some compile errors on Solaris. It irks me that the R Core Team insists on supporting a crufty compiler on an obsolete OS, when there is no support for Intel Parallel Studio on Windows. Even Microsoft R Open only supports GCC. I’m hoping that the new Windows Subsystem for Linux (WSL) might finally provide an option for compiling R packages with nVidia CUDA on Windows, but I haven’t had a chance to investigate yet. In the meantime, this post describes how I fixed the compile errors as well as another NOTE that had appeared in CRAN. These changes are available in version 0.4-0 of bayesImageS.

The C++ standard library in the OpenCSW version of GCC 5.2.0 is incompatible with GCC on other platforms (such as Windows, Linux and Mac OS). This causes errors like the following:

smcPotts.cpp: In function ‘Rcpp::IntegerVector resample_resid(Rcpp::NumericVector&, arma::vec&, Rcpp::NumericMatrix&)’:
smcPotts.cpp:219:48: error: call of overloaded ‘log(const unsigned int&)’ is ambiguous
       int tW = (int)trunc(exp(log_wt(i) + log(n)));
In file included from /usr/include/math.h:15:0,
                 from /opt/csw/include/c++/5.2.0/cmath:44,
                 from /home/ripley/R/Lib32/Rcpp/include/Rcpp/platform/compiler.h:100,
                 from /home/ripley/R/Lib32/Rcpp/include/Rcpp/r/headers.h:48,
                 from /home/ripley/R/Lib32/Rcpp/include/RcppCommon.h:29,
                 from /home/ripley/R/Lib32/RcppArmadillo/include/RcppArmadilloForward.h:26,
                 from /home/ripley/R/Lib32/RcppArmadillo/include/RcppArmadillo.h:31,
                 from smcPotts.h:4,
                 from smcPotts.cpp:20:
/opt/csw/lib/gcc/sparc-sun-solaris2.10/5.2.0/include-fixed/iso/math_iso.h:200:21: note: candidate: long double std::log(long double)
  inline long double log(long double __X) { return __logl(__X); }
/opt/csw/lib/gcc/sparc-sun-solaris2.10/5.2.0/include-fixed/iso/math_iso.h:168:15: note: candidate: float std::log(float)
  inline float log(float __X) { return __logf(__X); }
/opt/csw/lib/gcc/sparc-sun-solaris2.10/5.2.0/include-fixed/iso/math_iso.h:68:15: note: candidate: double std::log(double)
 extern double log __P((double));
*** Error code 1
make: Fatal error: Command failed for target `smcPotts.o'
Current working directory /tmp/RtmpPtailS/R.INSTALL5859270b1fe0/bayesImageS/src
ERROR: compilation failed for package ‘bayesImageS’

The Writing R Extensions manual describes this as an “overloading ambiguity,” in the section on Portable C and C++ code. Given that this code compiles fine on Gnu g++, LLVM clang++ (Xcode) and icpc (Intel Parallel Studio XE) on Windows, Mac OS and Linux, somehow I don’t think the problem with portability is at my end!

The fix is quite straightforward, albeit painstaking. It involves searching through the source code for every use of math.h functions log(), exp(), pow(), etc. for implicit casts from int/uint/long to float/double and making them explicit to resolve the “ambiguity.” For example, the fix for the code above was as follows:

>       int tW = (int)trunc(exp(log_wt(i) + log((double)n)));
<       int tW = (int)trunc(exp(log_wt(i) + log(n)));

Refer to checkin 4d1a7ec on BitBucket for details. I was pleased to see that the Solaris build on CRAN is now working:

using R Under development (unstable) (2017-03-21 r72378)
using platform: sparc-sun-solaris2.10 (32-bit)

I’m glad that I don’t have any issues with 32 vs. 64bit OS, that really would be annoying! If compile errors in OpenCSW on SPARC Solaris are considered as vital issues (i.e. your R package is scheduled for archival unless you fix them) then I hope that services like R-hub and Travis CI will eventually provide support for building on this platform. It’s been more than 15 years since the last time that I installed Solaris myself. Back then, I was paid to care about customers with obscure taste in operating systems. In the UK I don’t have a spare computer that I would want to sacrifice in such a pointless task.

When I came to submit this fix to CRAN, I saw that my build status had an additional NOTE that wasn’t there when the package was first submitted:

    Found no calls to: ‘R_registerRoutines’, ‘R_useDynamicSymbols’

It is good practice to register native routines and to disable symbol

See ‘Writing portable packages’ in the ‘Writing R Extensions’ manual.

Although this has only recently been added to the CRAN package checks, it has been a feature of R for a very long time. Duncan Temple Lang explained the technical details in an article for R News back in 2001 (Vol. 1/3, pp. 20-23). The idea is that you register every C, C++ or Fortran function explicitly with R so that it doesn’t have to search the dynamic symbol table every time you make a call. This is also safer, because R checks to make sure that .C() isn’t used for functions that require .Call() and vice-versa. All of the relevant code is in bayesImageS_init.cpp, which I created in checkin 60d8fa5. Note that this isn’t an issue for anyone who uses Rcpp attributes, since the RcppExports.cpp handles all of this for you (since Rcpp version 0.10.0). This gives me a further reason to rewrite this package to use annotations, since it will be easier to maintain in the long run.

I also had a lot of headaches with the LaTeX setup on my new laptop. Fortunately I could still refer to my old iMac to figure out what the problem was. One issue that I never managed to fix was that knitr wouldn’t convert EPS files to PDF. In the end, I just included the *-eps-converted-to.pdf files in the R package. This is also something that I’ll probably need to revisit in future, or it will keep coming back to bite me on the arse.


From → C++, R

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Ella Kaye on Ella Kaye

Computational Bayesian statistics

Bayes' Food Cake

A bit of statistics, a bit of cakes. - Blogs to Learn R from the Community

Computational Bayesian statistics

Richard Everitt's blog

Computational Bayesian statistics

Let's Look at the Figures

David Firth's blog

Nicholas Tierney

Computational Bayesian statistics

Sweet Tea, Science

Two southern scientistas will be bringing you all that is awesome in STEM as we complete our PhDs. Ecology, statistics, sass.

Mad (Data) Scientist

Musings, useful code etc. on R and data science

Another Astrostatistics Blog

The random musings of a reformed astronomer ...

Darren Wilkinson's research blog

Statistics, computing, data science, Bayes, stochastic modelling, systems biology and bioinformatics

(badness 10000)

Computational Bayesian statistics

Igor Kromin

Computational Bayesian statistics


I can't get no

Xi'an's Og

an attempt at bloggin, nothing more...

Sam Clifford

Postdoctoral Fellow, Bayesian Statistics, Aerosol Science

%d bloggers like this: