6

Our R installation define in:

R$HOME/etc/Makeconf that CC = gcc -std=gnu99 

I have one specific package (mix of C++ and C code) that need to be compiled using

  CC = gcc  

without -std=gnu99

As far as I understood I have 3 ways of doing that:
1) system wide, edit R$HOME/etc/Makeconf
2) per user basis, play with ~/.R/Makevars
3) per package basis, set PACKAGE/src/Makevars

Even if 1 and 2 is not what I want I tested the 3 options, using 1 and 2

R CMD INSTALL -l pack.tgz is OK "gcc -std=gnu99" is corectly replaced by "gcc"

But when using PACKAGE/src/Makevars approach it fails

I must admit that I'm lost at this point, where should I look ?

edit. this is not really a duplicate with Building R Packages using Alternate GCC for sure I have read the previous one.is the one that pointed me to Makevars

my key concern is that PACKAGE/src/Makevars is not taken in account for CC=alternate compiler while other one are working prefectly.

Community
  • 1
  • 1
  • 2
    Dirk's answer here http://stackoverflow.com/questions/1616983/building-r-packages-using-alternate-gcc points to #2 (and, implicitly, #1) as the likely solution as does http://r-pkgs.had.co.nz/src.html. – hrbrmstr Sep 21 '16 at 21:02
  • This is still not as clear or obvious as we would like it to be but between your question here and my earlier answer I think we have all bases covered. – Dirk Eddelbuettel Sep 21 '16 at 21:55
  • maybee this can help to understand. if ~/.R/Makevars contains CC=gcc, then R CMD SHLIB *.c compiles using gcc. - if no ~/.R/Makevars and CC=gcc in PACK/src/Makevars then R CMD SHLIB *.c compiles using gcc -std=gnu99 (ie the value of R CMD config CC) that let me say that PACK/src/Makevars is ignored, at least for CC definition. – Eric Deveaud Sep 22 '16 at 08:01

1 Answers1

2

I had a similar problem in fortran. Anyway I made a model of your package and I found an half solution. It seems that not all the variables in PACKAGE/src/Makevars are considered and used. In order to make it work I used this Makevars file:

MY_PKG_LIBS =
MY_PKG_CCLAGS = -I/usr/share/R/include -DNDEBUG -fpic  -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -D_FORTIFY_SOURCE=2 -g

all: $(SHLIB)                      
hello.o: hello.c
        gcc $(MY_PKG_CCLAGS) -c hello.c -o hello.o $(MY_PKG_LIBS)

PKG_LIB = -std=gnu++11

Obviously the hello.c file should be replaced by your_file_name.c. If you can not change the CC and you adopt my workaround, the real problem become that when the shared file .so is created, the compiler flags should be overwritten using PKG_CFLAGS or PKG_CPPFLAGS as stated in Writing R Extensions (again in the Makevars file). In my personal situation (Ubuntu 15.04, R 3.1.2), I tried those and other vars following the guidelines in /etc/R/Makeconf file:

ALL_CFLAGS = $(R_XTRA_CFLAGS) $(PKG_CFLAGS) $(CPICFLAGS) $(SHLIB_CFLAGS) $(CFLAGS)
ALL_CPPFLAGS = $(R_XTRA_CPPFLAGS) $(PKG_CPPFLAGS) $(CPPFLAGS) $(CLINK_CPPFLAGS)

The only thing that worked in adding a flag to the -shared final compiling of the package was adding the library linker flag (As I did originally with my fortran code) PKG_LIB = -std=gnu++11 in the PACKAGE/src/Makevars. My final result in installing the package is:

Installing package into ‘/home/home/R/x86_64-pc-linux-gnu-library/3.1’
(as ‘lib’ is unspecified)
* installing *source* package ‘question1’ ...
** libs
gcc -I/usr/share/R/include -DNDEBUG -fpic  -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -D_FORTIFY_SOURCE=2 -g -c hello.c -o hello.o 
gcc -std=gnu99 -shared -L/usr/lib/R/lib -Wl,-Bsymbolic-functions -Wl,-z,relro -o question1.so hello.o -std=gnu++11 -L/usr/lib/R/lib -lR
installing to /home/dgarolini/R/x86_64-pc-linux-gnu-library/3.1/question1/libs
** R
** preparing package for lazy loading
** help
*** installing help indices
** building package indices
** testing if installed package can be loaded
* DONE (question1)
Garini
  • 1,088
  • 16
  • 29