[R] Makefile to compile .so in src (was: Re: automated libR location)

Uwe Ligges ligges at statistik.tu-dortmund.de
Thu Feb 2 12:06:14 CET 2012



On 01.02.2012 03:37, Matyas Sustik wrote:
> Prof Brian Ripley wrote:
>> 'library' in R has a different meaning: I've altered the subject to be
>> more accurate 'libR'.
>>
>> This is what R CMD SHLIB is for: it does all this for you in a portable way.
>>
>> But if you want to DIY, you can use R CMD config to find out the
>> appropriate linker incantation.
>
> Thank you for the clarification.  I do not insist on doing it myself
> and would welcome
> R doing it automatically.  I guess I did not fully understand the
> instructions in the
> document "R Extensions".  (English is my second language.)
>
> A small example compiling a single .so would help greatly I think.  My
> current Makefile
> that I put in src of  a package skeleton looks like this to create the
> .so on Linux:
>
> all :  QUIC.so
>
> OBJECTS = QUIC.o QUIC.so
>
> PKG_LIBS = @LAPACK_LIBS@ @BLAS_LIBS@
>
> QUIC.o : QUIC.cpp
>         g++ -O3 -DNDEBUG -Wall -fpic -pthread -shared
> -fno-omit-frame-pointer -ansi -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -c
> QUIC.cpp -o QUIC.o
>
> QUIC.so : QUIC.o
> 	g++ -std=gnu99  -shared -lm -llapack -lblas -L/usr/lib/R/lib -lR -O3
> QUIC.o -o QUIC.so


1. I don't believe you really need all the flags from above. If so, 
within a package, use a Makevars file.

2. R CMD SHLIB QUIC.cpp shoudl do the trick already, perhaps some linker 
flags are required for blas that can be specified in the same line, see 
R CMD SHLIB --help

Uwe Ligges






> This actually built and created a loadable package but I would want to
> do it more the R-way.
>
> Thanks in advance!
> -Matyas
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list