Skip to content

[Rcpp-devel] Issues creating static library using Makevars

6 messages · Akhila Chowdary Kolla, Dirk Eddelbuettel, Toby Hocking

#
Hello Everyone,

I am trying to generate a C static library(libdeepstate.a) in an
Rcpp(inst/include/lib) package using Makevars similar to RInside(generating
RInside.so and RInside.a)
My static library libdeepstate.a  has four compiled c programs
[image: image.png]

I saved those files DeepState.c, Log.c,Option.c,Stream.c in inst/include
folder and using src/Makevars to compile those *.c files and link the
respective object files with the static library as follows:
src/Makevars:
USERLIBST=libdeepstate.a
USERDIR=../inst/lib
PKG_CPPFLAGS =-I. -I../inst/include/
PKG_LIBS =
all: $(SHLIB) userLibrary
SOURCES= ../inst/include/DeepState.c ../inst/include/Log.c
../inst/include/Option.c ../inst/include/Stream.c
OBJECTS= $(SOURCES:.c=.o)
userLibrary: $(USERLIBST)
- at if test ! -e $(USERDIR)$(R_ARCH); then mkdir -p $(USERDIR)$(R_ARCH); fi
cp $(USERLIBST) $(USERDIR)$(R_ARCH)
rm $(USERLIBST)

*$(USERLIBST): $(OBJECTS)$(AR) qc $(USERLIBST) $^*
@if test -n "$(RANLIB)"; then $(RANLIB) $(USERLIBST); fi

When I install the package I get something like this :







*gcc -I"/home/akhila/lib/R/include" -DNDEBUG -I. -I../inst/include/
-I/usr/local/include  -fpic  -g -O2  -c ../inst/include/DeepState.c -o
../inst/include/DeepState.ogcc -I"/home/akhila/lib/R/include" -DNDEBUG -I.
-I../inst/include/   -I/usr/local/include  -fpic  -g -O2  -c
../inst/include/Log.c -o ../inst/include/Log.ogcc
-I"/home/akhila/lib/R/include" -DNDEBUG -I. -I../inst/include/
-I/usr/local/include  -fpic  -g -O2  -c ../inst/include/Option.c -o
../inst/include/Option.ogcc -I"/home/akhila/lib/R/include" -DNDEBUG -I.
-I../inst/include/   -I/usr/local/include  -fpic  -g -O2  -c
../inst/include/Stream.c -o ../inst/include/Stream.ogcc -shared
-L/home/akhila/lib/R/lib -L/usr/local/lib -o testproject.so
../inst/include/DeepState.o ../inst/include/Log.o ../inst/include/Option.o
../inst/include/Stream.o -L/home/akhila/lib/R/lib -lRar qc libdeepstate.a
../inst/include/DeepState.o ../inst/include/Log.o ../inst/include/Option.o
../inst/include/Stream.ocp libdeepstate.a ../inst/lib*
*rm libdeepstate.a*

The code can be found in GitHub:https://github.com/akhikolla/RcppDeepState/
This Travis build has the complete details of the warnings:
https://travis-ci.org/github/akhikolla/RcppDeepState/builds/702470420
But when I check the package I get the following warnings: using
devtools::check()
*W  checking pragmas in C/C++ headers and code ... WARNING*





































*   File which contains non-portable pragma(s)     ‘inst/include/Log.c’
 File which contains pragma(s) suppressing diagnostics:
 ‘inst/include/Log.c’✓  checking compilation flags used ...W  checking
compiled code ...   File ‘testproject/libs/testproject.so’:     Found
‘__assert_fail’, possibly from ‘assert’ (C)       Object:
‘../inst/include/DeepState.o’     Found ‘__printf_chk’, possibly from
‘printf’ (C)       Objects: ‘../inst/include/DeepState.o’,
‘../inst/include/Log.o’     Found ‘abort’, possibly from ‘abort’ (C)
 Object: ‘../inst/include/DeepState.o’     Found ‘exit’, possibly from
‘exit’ (C)       Objects: ‘../inst/include/DeepState.o’,
‘../inst/include/Option.o’     Found ‘printf’, possibly from ‘printf’ (C)
     Object: ‘../inst/include/Log.o’     Found ‘puts’, possibly from
‘printf’ (C), ‘puts’ (C)       Objects: ‘../inst/include/DeepState.o’,
‘../inst/include/Log.o’     Found ‘rand’, possibly from ‘rand’ (C)
 Object: ‘../inst/include/DeepState.o’     Found ‘srand’, possibly from
‘srand’ (C)       Object: ‘../inst/include/DeepState.o’     Found ‘stderr’,
possibly from ‘stderr’ (C)       Object: ‘../inst/include/Log.o’     Found
‘stdout’, possibly from ‘stdout’ (C)       Object: ‘../inst/include/Log.o’
   Found ‘vprintf’, possibly from ‘vprintf’ (C)       Object:
‘../inst/include/Log.o’   File ‘testproject/libs/testproject.so’:     Found
no calls to: ‘R_registerRoutines’, ‘R_useDynamicSymbols’    Compiled code
should not call entry points which might terminate R nor write to
stdout/stderr instead of to the console, nor use Fortran I/O nor system
RNGs. It is good practice to register native routines and to disable
symbol search.*

  *Found no calls to: ‘R_registerRoutines’, ‘R_useDynamicSymbols’  - why is
this necessary as I am trying to compile some external C
files(inst/include/DeepState.c) which are not in src folder*
   *Compiled code should not call entry points which might terminate R
nor write to stdout/stderr instead of to the console, nor use Fortran
I/O nor system RNGs. - what does this mean?*
how can I solve this issue and get rid of the warning in the R CMD check?
Can someone please suggest a way to resolve this?


Regards,
Akhila Chowdary Kolla
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20200626/85505235/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image.png
Type: image/png
Size: 19482 bytes
Desc: not available
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20200626/85505235/attachment-0001.png>
#
On 26 June 2020 at 15:55, Akhila Chowdary Kolla wrote:
| But when I check the package I get the following warnings: using
| devtools::check()
| ‘../inst/include/Log.o’   File ‘testproject/libs/testproject.so’:     Found
| no calls to: ‘R_registerRoutines’, ‘R_useDynamicSymbols’    Compiled code
| should not call entry points which might terminate R nor write to
| stdout/stderr instead of to the console, nor use Fortran I/O nor system
| RNGs. It is good practice to register native routines and to disable
| symbol search.*

See "Writing R Extensions"
 
|   *Found no calls to: ‘R_registerRoutines’, ‘R_useDynamicSymbols’  - why is

See "Writing R Extensions"

| this necessary as I am trying to compile some external C
| files(inst/include/DeepState.c) which are not in src folder*
|    *Compiled code should not call entry points which might terminate R
| nor write to stdout/stderr instead of to the console, nor use Fortran
| I/O nor system RNGs. - what does this mean?*

See "Writing R Extensions"

| how can I solve this issue and get rid of the warning in the R CMD check?
| Can someone please suggest a way to resolve this?

See "Writing R Extensions" -- nobody here on the list "makes the rules". Only
R Core / CRAN do. We all just try live by them.

Dirk
#
Right, Writing R Extensions is a great reference.
To clarify the question, we are developing a package like RInside, which
contains some compiled C++ code that is not meant to be used from R main.
We would like to distribute the C++ source code in an R package (like
RInside), so we are trying to figure out how RInside managed to do this and
satisfy CRAN checks.
Looking at current CRAN checks for RInside
https://cloud.r-project.org/web/checks/check_results_RInside.html I see
some similar NOTE / WARNING ... are these new in the last few months, or
were they there when you submitted to CRAN? i.e. did CRAN accept the
submission even with such NOTE / WARNING? Just trying to figure out the
best way to package this compiled code so that CRAN will accept it.
Any tips/tricks you have discovered from your experience with RInside would
be appreciated.
Toby
On Fri, Jun 26, 2020 at 8:08 PM Dirk Eddelbuettel <edd at debian.org> wrote:

            
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20200627/ee9e3382/attachment.html>
#
Toby,

Well but not one of the questions raised by Akhila had anything to do with an
static library.  The questions were, in turn, about

 - not calling exit() and like

 - need to call ‘R_registerRoutines’, ‘R_useDynamicSymbols’

 - not use system RNGs

all of which are standard packaging issues, unrelated to Rcpp or to the
creation of a static library.

I fear you need to get that code in order before you have to worry about how
you ship, static or shared library.

Dirk
#
Toby, Akhila,

My bad, I'm sorry!

So I went back glancing at

  https://cloud.r-project.org/web/checks/check_results_RInside.html

and the only clear suggestion is that one would probably no longer get a
package like that admitted. That is potentially bad news for your project.

Sorry to be bearer of bad news, but I do not make or impose these rules.

Dirk
1 day later
#
Hi Dirk thanks for the feedback. So I guess that means those are new
WARNING messages on CRAN that were not there at the time RInside was
accepted on CRAN, right?
I would suggest moving the discussion to R-pkg-devel to see if CRAN could
recommend a way to support install-time compilation of the static library
that we need.
If CRAN is not willing/able to accommodate that, we could just put the C++
source code somewhere other than pkg/src, and then compile it AFTER the
package has been installed, when the user requests that we fuzz their Rcpp
package. That won't be much of a drawback / portability issue, because
anyways the main functionality of our package requires a compiler on the
user's system.
On Sat, Jun 27, 2020 at 4:51 PM Dirk Eddelbuettel <edd at debian.org> wrote:

            
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20200629/862d72fb/attachment.html>