[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

How can I change the Makeconf file of R to not use hardcoded, wrong incl

From: Moritz Lell
Subject: How can I change the Makeconf file of R to not use hardcoded, wrong include paths when compiling a package with Rcpp
Date: Tue, 14 Jan 2020 00:49:31 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.3.1


to reproduce a scientific project, I need a setup with an old R version
(3.4.3), together with other, newer libraries. I created a profile, the
manifest and package definitions are below. However, when loading the
profile I cannot compile R packages with this version:

The last lines of the output of `install.packages("Rcpp_1.0.3.tar.gz",
repos = NULL)` (I have to manually download/use the miniCRAN package
because of SSL errors while downloading via R but that is another question)

--- begin --------------------------------------------------------------

g++ -shared
-L/usr/local/lib -o api.o attributes.o barrier.o date.o module.o
-L/gnu/store/d64gfblqc5b9gmwj3rbl8nx3zwbf973b-r-minimal-3.4.3/lib/R/lib -lR
installing to
** R
** inst
** preparing package for lazy loading
code for methods in class “C++OverloadedMethods” was not checked for
suspicious field assignments (recommended package ‘codetools’ not
code for methods in class “RcppClass” was not checked for suspicious
field assignments (recommended package ‘codetools’ not available?)
code for methods in class “RcppClass” was not checked for suspicious
field assignments (recommended package ‘codetools’ not available?)
** help
*** installing help indices
** building package indices
** installing vignettes
** testing if installed package can be loaded
Error: package or namespace load failed for ‘Rcpp’ in dyn.load(file,
DLLpath = DLLpath, ...):
 kann shared object
nicht laden:

version `GLIBCXX_3.4.26' not found (required by

--- end ---------------------------------------------------------------

The problem is `-I/usr/local/include` in the g++ call. It refers to a
directory outside of my GUIX installation and hence I get errors because
libraries there mismatch with those inside GUIX. Apparently, GUIX libs
are used for the linker but not for the compiler.

The problem lies in the file

--- begin ------------------------------------------------------------

CPPFLAGS = -I/usr/local/include
-lgfortran -lm -lquadmath

--- end --------------------------------------------------------------

CPPFLAGS is set to the wrong, hardcoded value, but for example FLIBS is
set correctly. How can I install R such that CPPFLAGS refers to the
/lib/include directory of my profile or doesn't refer to anything?

I can define the PKG_CXXFLAGS environment variable that can be used to
insert additional header locations for R compilation, but unfortunately
they are inserted after the R default locations. But I can use it if the
R default is set to nothing. I've also tested setting CPLUS_INCLUDE_PATH
and PKG_CPPFLAGS, to no avail.



Appendix: Profile manifests and other files

manifest.scm            --- manifest file for guix package
packages/               --- include in GUIX_PACKAGE_PATH
packages/statistics.scm --- Checked out from the guix repo with
    `git show cbe1314a7e:gnu/packages/statistics.scm` and edited
    to only include r-minimal
packages/old-tzdata.scm --- for the package tzdata-2017b

# Commands to create the files needed to reproduce the problem
mkdir packages

cat >manifest.scm <<EOF



# ----------------------------------------------------------------------

cat >packages/old-tzdata.scm <<EOF

(define-module (old-tz-data)
  #:use-module ((guix licenses)
                #:select (gpl3+ lgpl2.0+ lgpl3+ public-domain))
  #:use-module (guix utils)
  #:use-module (guix packages)
  #:use-module (guix download)
  #:use-module (guix build-system gnu)
  #:use-module (guix build-system trivial)
(define tzdata
    (name "tzdata")
    (version "2017b")
    (source (origin
             (method url-fetch)
             (uri (string-append

                   version ".tar.gz"))
    (build-system gnu-build-system)
     '(#:tests? #f
       #:make-flags (let ((out (assoc-ref %outputs "out"))
                          (tmp (getenv "TMPDIR")))
                      (list (string-append "TOPDIR=" out)
                            (string-append "TZDIR=" out "/share/zoneinfo")

                            ;; Discard zic, dump, and tzselect, already
                            ;; provided by glibc.
                            (string-append "ETCDIR=" tmp "/etc")

                            ;; Likewise for the C library routines.
                            (string-append "LIBDIR=" tmp "/lib")
                            (string-append "MANDIR=" tmp "/man")

       #:modules ((guix build utils)
                  (guix build gnu-build-system)
                  (srfi srfi-1))
       (modify-phases %standard-phases
         (replace 'unpack
           (lambda* (#:key source inputs #:allow-other-keys)
             (and (zero? (system* "tar" "xvf" source))
                  (zero? (system* "tar" "xvf" (assoc-ref inputs
         (add-after 'install 'post-install
           (lambda* (#:key outputs #:allow-other-keys)
             ;; Move data in the right place.
             (let ((out (assoc-ref outputs "out")))
               (symlink (string-append out "/share/zoneinfo")
                        (string-append out "/share/zoneinfo/posix"))
                (string-append out "/share/zoneinfo-posix"))
               (copy-recursively (string-append out "/share/zoneinfo-leaps")
                                 (string-append out
                (string-append out "/share/zoneinfo-leaps")))))
         (delete 'configure))))
    (inputs `(("tzcode" ,(origin
                          (method url-fetch)
                          (uri (string-append

                                version ".tar.gz"))

    (home-page "";)
    (synopsis "Database of current and historical time zones")
    (description "The Time Zone Database (often called tz or zoneinfo)
contains code and data that represent the history of local time for many
representative locations around the globe.  It is updated periodically to
reflect changes made by political bodies to time zone boundaries, UTC
and daylight-saving rules.")
    (license public-domain)))

(define-public tzdata-2017a
    (inherit tzdata)
    (version "2017a")
        (method url-fetch)
        (uri (string-append "";
                            "/releases/tzdata" version ".tar.gz"))
    (inputs `(("tzcode" ,(origin
                          (method url-fetch)
                          (uri (string-append

                                version ".tar.gz"))



# ----------------------------------------------------------------------

cat >packages/statistics.scm <<EOF

(define-module (statistics)
  #:use-module (old-tz-data)
  #:use-module ((guix licenses) #:prefix license:)
  #:use-module (guix packages)
  #:use-module (guix download)
  #:use-module (guix hg-download)
  #:use-module (guix utils)
  #:use-module (guix build-system gnu)
  #:use-module (guix build-system r)
  #:use-module (guix build-system python)
  #:use-module (guix build-system trivial)
  #:use-module (gnu packages)
  #:use-module (gnu packages check)
  #:use-module (gnu packages compression)
  #:use-module (gnu packages cran)
  #:use-module (gnu packages curl)
  #:use-module (gnu packages gcc)
  #:use-module (gnu packages gtk)
  #:use-module (gnu packages gettext)
  #:use-module (gnu packages glib)
  #:use-module (gnu packages haskell)
  #:use-module (gnu packages icu4c)
  #:use-module (gnu packages image)
  #:use-module (gnu packages java)
  #:use-module (gnu packages machine-learning)
  #:use-module (gnu packages maths)
  #:use-module (gnu packages multiprecision)
  #:use-module (gnu packages pcre)
  #:use-module (gnu packages perl)
  #:use-module (gnu packages pkg-config)
  #:use-module (gnu packages python)
  #:use-module (gnu packages readline)
  #:use-module (gnu packages ssh)
  #:use-module (gnu packages texinfo)
  #:use-module (gnu packages time)
  #:use-module (gnu packages tls)
  #:use-module (gnu packages base)
  #:use-module (gnu packages web)
  #:use-module (gnu packages xml)
  #:use-module (gnu packages xorg)
  #:use-module (srfi srfi-1))

;; Update this package together with the set of recommended packages:
;; r-class, r-cluster, r-codetools, r-foreign, r-kernsmooth, r-lattice,
;; r-mass, r-matrix, r-mgcv, r-nlme, r-nnet, r-rpart, r-spatial, r-survival.

(define-public r-minimal
    (name "r-minimal")
    (version "3.4.3")
    (source (origin
              (method url-fetch)
              (uri (string-append "mirror://cran/src/base/R-"
                                  (version-prefix version 1) "/R-"
                                  version ".tar.gz"))
    (build-system gnu-build-system)
     `(#:disallowed-references (,tzdata-2017a)
       (list (string-append "LDFLAGS=-Wl,-rpath="
                            (assoc-ref %outputs "out")
             ;; This affects the embedded timestamp of only the core
       (modify-phases %standard-phases
         (add-before 'configure 'do-not-compress-serialized-files
           (lambda* (#:key inputs #:allow-other-keys)
             ;; This ensures that Guix can detect embedded store references;
             ;; see bug #28157 for details.
             (substitute* "src/library/base/makebasedb.R"
               (("compress = TRUE") "compress = FALSE"))
         (add-before 'configure 'patch-uname
           (lambda* (#:key inputs #:allow-other-keys)
             (let ((uname-bin (string-append (assoc-ref inputs "coreutils")
               (substitute* "src/scripts/"
                 (("uname") uname-bin)))
         (add-after 'unpack 'build-reproducibly
           (lambda _
             ;; The documentation contains time stamps to demonstrate
             ;; documentation generation in different phases.
             (substitute* "src/library/tools/man/Rd2HTML.Rd"
               (("\\\\%Y-\\\\%m-\\\\%d at \\\\%H:\\\\%M:\\\\%S")
                "(removed for reproducibility)"))

             ;; Remove timestamp from tracing environment.  This fixes
             ;; reproducibility of "methods.rd{b,x}".
             (substitute* "src/library/methods/R/trace.R"
               (("dateCreated = Sys.time\\(\\)")
                "dateCreated = as.POSIXct(\"1970-1-1 00:00:00\", tz =

             ;; Ensure that gzipped files are reproducible.
             (substitute* '("src/library/grDevices/"
               (("R_GZIPCMD\\)" line)
                (string-append line " -n")))

             ;; The "srcfile" procedure in "src/library/base/R/srcfile.R"
             ;; queries the mtime of a given file and records it in an
             ;; This is acceptable at runtime to detect stale source files,
             ;; but it destroys reproducibility at build time.
             ;; Instead of disabling this feature, which may have unexpected
             ;; consequences, we reset the mtime of generated files before
             ;; passing them to the "srcfile" procedure.
             (substitute* "src/library/"
               (("@\\(cd base && \\$\\(MAKE\\) mkdesc\\)" line)
                (string-append line "\n find
$(top_builddir)/library/tools | xargs touch -d '1970-01-01'; \n"))
               (("@\\$\\(MAKE\\) Rdobjects" line)
                (string-append "@find $(srcdir)/tools | xargs touch -d
'1970-01-01'; \n        "
             (substitute* "src/library/tools/"
               (("@\\$\\(INSTALL_DATA\\) all.R
\\$\\(top_builddir\\)/library/\\$\\(pkg\\)/R/\\$\\(pkg\\)" line)
                 "\n    find $(srcdir)/$(pkg)
$(top_builddir)/library/$(pkg) | xargs touch -d \"1970-01-01\"; \n")))

             ;; This library is installed using
             ;; so we need to pass the "builtStamp" argument.
             (substitute* "src/library/tools/"
               (("(install_package_description\\(.*\"')\\)\"" line prefix)
                (string-append prefix ", builtStamp='1970-01-01')\"")))

             ;; R bundles an older version of help2man, which does not
             ;; SOURCE_DATE_EPOCH.  We cannot just use the latest help2man,
             ;; because that breaks a test.
             (with-fluids ((%default-port-encoding "ISO-8859-1"))
               (substitute* "tools/"
                 (("my \\$date = strftime \"%B %Y\", localtime" line)
                  (string-append line " 1"))))
         (add-before 'configure 'set-default-pager
          ;; Set default pager to "cat", because otherwise it is "false",
          ;; making "help()" print nothing at all.
          (lambda _ (setenv "PAGER" "cat") #t))
         (add-before 'check 'set-timezone
           ;; Some tests require the timezone to be set.  However, the
           ;; timezone may not just be "UTC", or else a brittle regression
           ;; test in reg-tests-1d will fail.
           (lambda* (#:key inputs #:allow-other-keys)
             (setenv "TZ" "UTC+1")
             (setenv "TZDIR"
                     (string-append (assoc-ref inputs "tzdata")
         (add-after 'build 'make-info
          (lambda _ (zero? (system* "make" "info"))))
         (add-after 'build 'install-info
          (lambda _ (zero? (system* "make" "install-info")))))
       '(;; Do not build the recommended packages.  The build system creates
         ;; random temporary directories and embeds their names in some
         ;; package files.  We build these packages with the r-build-system
         ;; instead.
    ;; R has some support for Java.  When the JDK is available at configure
    ;; time environment variables pointing to the JDK will be recorded under
    ;; $R_HOME/etc and ./tools/ will be compiled which is used
by "R
    ;; CMD javareconf".  "R CMD javareconf" appears to only be used to
    ;; the recorded environment variables in $R_HOME/etc.  Refer to
    ;; for additional information.

    ;; As the JDK is a rather large input with only very limited effects
on R,
    ;; we decided to drop it.
     `(("bzip2" ,bzip2)
       ("perl" ,perl)
       ("pkg-config" ,pkg-config)
       ("texinfo" ,texinfo) ; for building HTML manuals
       ("tzdata" ,tzdata-2017a)
       ("xz" ,xz)))
     `(;; We need not only cairo here, but pango to ensure that tests
for the
       ;; "cairo" bitmapType plotting backend succeed.
       ("pango" ,pango)
       ("coreutils" ,coreutils)
       ("curl" ,curl)
       ("openblas" ,openblas)
       ("gfortran" ,gfortran)
       ("icu4c" ,icu4c)
       ("libjpeg" ,libjpeg)
       ("libpng" ,libpng)
       ("libtiff" ,libtiff)
       ("libxt" ,libxt)
       ("pcre" ,pcre)
       ("readline" ,readline)
       ("which" ,which)
       ("zlib" ,zlib)))
     (list (search-path-specification
            (variable "R_LIBS_SITE")
            (files (list "site-library/")))))
    (home-page "";)
    (synopsis "Environment for statistical computing and graphics")
     "R is a language and environment for statistical computing and
It provides a variety of statistical techniques, such as linear and
modeling, classical statistical tests, time-series analysis, classification
and clustering.  It also provides robust support for producing
publication-quality data plots.  A large amount of 3rd-party packages are
available, greatly increasing its breadth and scope.")
    (license license:gpl3+)))


reply via email to

[Prev in Thread] Current Thread [Next in Thread]