Hello,

I've been trying to make LinkingTo work when the package linked to has c++ code.

I've put dumb packages to illustrate this emails here ; http://addictedtor.free.fr/misc/linkingto

Package A defines this C++ class:

class A {
public:
        A() ;
        ~A() ;
        SEXP hello() ;
} ;

Package B has this function :

SEXP say_hello(){
        A a ;
        return a.hello() ;
}

headers of package A are copied into inst/include so that package B can have.

LinkingTo: A

in its DESCRIPTION file.

Also, package B has the R function ;

g <- function(){
        .Call("say_hello", PACKAGE = "B")
}

With this I can compile A and B, but then I get :

$ Rscript -e "B::g()"
Error in dyn.load(file, DLLpath = DLLpath, ...) :
  unable to load shared library '/usr/local/lib/R/library/B/libs/B.so':
  /usr/local/lib/R/library/B/libs/B.so: undefined symbol: _ZN1AD1Ev
Calls: :: ... tryCatch -> tryCatchList -> tryCatchOne -> <Anonymous>

If I then add a Makevars in B with this :


# find the root directory where A is installed
ADIR=$(shell $(R_HOME)/bin/Rscript -e "cat(system.file(package='A'))" )

PKG_LIBS= $(ADIR)/libs/A$(DYLIB_EXT)


Then it works:

$ Rscript -e "B::g()"
[1] "hello"

So it appears that adding the -I flag, which is what LinkingTo does is not enough when the package "linking from" (B) actually has to link to the "linked to" package (A).

I've been looking at http://cran.r-project.org/doc/manuals/R-exts.html#Registering-native-routines but it seems only applicable to c(++) functions and not classes ...

What am I missing ? Should/can linkingto be extended in a way that accomodates c++

Romain


--
Romain Francois
Professional R Enthusiast
+33(0) 6 28 91 30 30
http://romainfrancois.blog.free.fr
|- http://tr.im/NrTG : Rcpp 0.7.5
|- http://tr.im/MPYc : RProtoBuf: protocol buffers for R
`- http://tr.im/KfKn : Rcpp 0.7.2

______________________________________________
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel

Reply via email to