0

I would like to be able to use Guile from within R but I don't want RcppGuile::call_guile taking so long to initialize Guile every time. Ideally, Guile could initialize into a reusable object on the R side given a source file. I wanted to poke around to see if that could be simple to do. Unfortunately, I don't really understand how Makevars is supposed to work and so cannot even get the package to load when calling from devtools::load_all().

I think the problem is that RcppGuile Makevars are hardcoded for Debian based GNU/Linux systems. I am running GNU/Guix which works differently.

I tried modifying the Makevars to be:

PKG_CXXFLAGS = -I"/home/wdkrnls/my/system/rstats/include/guile/3.0"
PKG_LIBS = -lguile-3.0 -lgc

Then I tried to run devtools::load_all().

Unfortunately, it didn't work.

file/site-library/Rcpp/include' -I/usr/local/include  -I"/gnu/store/w8wd314qgq3r3nd73imr7amzs8cz4fnp-profile/include:/home/wdkrnls/my/system/rstats/include/guile/3.0" -fpic  -g -O2  -UNDEBUG -Wall -pedantic -g -O0 -fdiagnostics-color=always -c guile.cpp -o guile.o
   guile.cpp:4:10: fatal error: libguile.h: No such file or directory
       4 | #include <libguile.h>
         |          ^~~~~~~~~~~~
   compilation terminated.

Yet:

file.exists("/home/k/my/system/rstats/include/guile/3.0/libguile.h") # => TRUE

Then I tried to modify Makevars with instead:

PKG_CXXFLAGS = -I"../include/guile/3.0"
PKG_LIBS = -lguile-3.0 -lgc

But I got the same result with only the path changing. Can someone give me a hint as to what I am missing?

wdkrnls
  • 4,548
  • 7
  • 36
  • 64
  • 1
    The vignette [on build Rcpp with external libraries](https://cloud.r-project.org/web/packages/Rcpp/vignettes/Rcpp-libraries.pdf) tries to address this. Maybe it can help you a little? Your issue is mostly basic R package mechanics but we can try to help. – Dirk Eddelbuettel Aug 23 '22 at 11:51
  • Coming at this fresh, I think even a closer reading of the Rcpp gallery [page](https://gallery.rcpp.org/articles/guile-via-rcpp/) would have helped move the needle forward for me. It mentions that `guile-config link` and `guile-config compile` can help find the appropriate settings for my system. – wdkrnls Aug 23 '22 at 13:05
  • On Guix, those commands turned out to be: `-L/gnu/store/1jgcbdzx2ss6xv59w55g3kr3x4935dfb-guile-3.0.8/lib -L/gnu/store/2lczkxbdbzh4gk7wh91bzrqrk7h5g1dl-libgc-8.0.4/lib -lguile-3.0 -lgc` and `-pthread -I/gnu/store/1jgcbdzx2ss6xv59w55g3kr3x4935dfb-guile-3.0.8/include/guile/3.0`. – wdkrnls Aug 23 '22 at 13:07
  • Is there a more abstract way to do this? If I rebuild my profile (say, by performing a system update), all those hashes are going to change. – wdkrnls Aug 23 '22 at 13:18
  • 1
    See the vignette, and what it recommends for script `configure` calling `pkg-config` to get compiler and linker instructions. _Many_ R packages on CRAN do that, there is nothing special here because of either `Rcpp` or `Guile` -- you need to tell R _where headers_ and _which libraries from where_ to link against. – Dirk Eddelbuettel Aug 23 '22 at 13:21
  • Again, the RcppGallery suggests the next step: "A proper package would need to discover these from a script, typically configure, or Makefile invocations." – wdkrnls Aug 23 '22 at 13:21
  • 1
    Yes, that is the standard and documented way, both in Writing R Extensions (comes with your copy of R) and in the Rcpp vignette (that comes with your copy of Rcpp) that I alluded too. _Many_ packages do just this, [here is one I helped recently](https://github.com/stla/delaunay/blob/master/configure), and here is a [recent one of mine](https://github.com/eddelbuettel/rcpphwloc/blob/master/configure). If you have more specific questions you need to ask them. – Dirk Eddelbuettel Aug 23 '22 at 13:27
  • No, I think that you answered my real question, which while it may have been answered in the fine manual already, my brain could not compile down into a definite process because it has been spoiled with the high level nature of R for too long. I think the comments here contain the information I was looking for and I would immediately accept as an answer to my question. – wdkrnls Aug 23 '22 at 13:34
  • This really is a duplicate a few times over so I just going to close it. Feel free to upvote the functionally identical answer in the linked-to thread. – Dirk Eddelbuettel Aug 23 '22 at 13:51

0 Answers0