Skip to content

[Rcpp-devel] Creating an R package using an existing .so file

6 messages · Jon Davidson, Jeff Newmiller, Peter Crowther +2 more

#
Hi,

I have an existing Rcpp module that has already been compiled into a .so.
How can I integrate this into an R package? The existing vignette for
packaging an Rcpp module involves including the C++ source in the package
folder, which will not be feasible for my setup. I can, however, have the
compiled .so file in the folder. Thanks for your help!

Best,
Jon
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20201104/20d18dab/attachment.html>
1 day later
#
On 4 November 2020 at 15:24, Jon Davidson wrote:
| I have an existing Rcpp module that has already been compiled into a .so.
| How can I integrate this into an R package?

I am afraid you can't as an .so file can only be used on one architecture,
and likely one subsets thereof (i.e. a Debian object file may not work on
Fedora, or Ubuntu, or maybe even a different Debian version).

That is why "the documentation" (ie WRE, CRAN Policy) say source only.

| The existing vignette for packaging an Rcpp module involves including the
| C++ source in the package folder, which will not be feasible for my
| setup. I can, however, have the compiled .so file in the folder. Thanks for
| your help!

Dirk
#
Also, it is important that all compiler flags are set consistently among all compilation units to insure proper linkage, and this policy helps keep those settings in one place.
On November 5, 2020 6:10:55 PM PST, Dirk Eddelbuettel <edd at debian.org> wrote:

  
    
#
On Fri, 6 Nov 2020 at 02:11, Dirk Eddelbuettel <edd at debian.org> wrote:

            
If you *really* wanted to go down this path, you could write a shim and
distribute that as source.  That shim could then somehow deduce the
appropriate compiled version and load it; the shim could, if you wished,
even download it.

This approach has the following notable points:

* If the Rcpp module depends on any part of Rcpp (it will!) and has been
compiled, whether into a .so or something else, then **it is already bound
by the terms of GPLv2 or later** (see the Rcpp FAQ 1.5).  If you distribute
the compiled work, then the infectious nature of GPL means you must also
make the source available.  Rcpp does not provide a way of distributing
compiled modules as a way of protecting IP, which I suspect is what you're
trying to do here.

* Your module would not be accepted by CRAN, so you would need your own
distribution mechanism.

* As Dirk points out, compiled code is not portable between OSs and
architectures, and often not between versions or distributions of one OS.
If you go down this route, expect to have to provide many different .so
files, including for some very unusual systems - which in turn means you'll
end up buying/renting tin for odd systems *or* not supplying your module
for them.  Fancy compiling for the Raspberry Pi?  At least that's only
$35.  How about IBM's Power9 architecture?

My suggestion, I'm afraid, would be "Yeah.  Don't do that."

Cheers,

- Peter
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20201106/fe6f0154/attachment.html>
#
Hi Jon,

I'm not sure why publishing the C++ source along with your package is not
feasible for you. If it is because of something besides technical
difficulty, you might need to consider an alternative method. Since the R
package must be portable, your secret functions must also be portable. You
can implement your functions on some portable platforms(e.g. JAVA) and
integrate it into your package. The road would not be easy, so I strongly
recommend you to try every other possibility before doing so.

Cheers,
Jiefei
On Thu, Nov 5, 2020 at 5:24 AM Jon Davidson <jondavidson47 at gmail.com> wrote:

            
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20201106/06ed1d48/attachment.html>
#
On 6 November 2020 at 22:45, Jiefei Wang wrote:
| I'm not sure why publishing the C++ source along with your package is not
| feasible for you. If it is because of something besides technical
| difficulty, you might need to consider an alternative method. Since the R
| package must be portable, your secret functions must also be portable. You
| can implement your functions on some portable platforms(e.g. JAVA) and
| integrate it into your package. The road would not be easy, so I strongly
| recommend you to try every other possibility before doing so.

This is getting off-topic fast: even C code can be portable (one binary per
platform) and that scheme is allowed on CRAN and used by a few packages.

It just can't be C++ for reasons that have to do with the language and
compiler. So for 'simple' Rcpp code, just ship the source.  And as R, CRAN,
Rcpp, ... are all open source that is the right play anyway.

Dirk