Aquarius_Girl
Aquarius_Girl

Reputation: 22926

How to place `library (RgoogleMaps)` inside the code of Rcpp?

#include "rtest.h"
#include <iostream>

SEXP rcpp_hello_world ()
{
    using namespace Rcpp ;
    CharacterVector x = CharacterVector::create( "foo", "bar" );
    NumericVector y   = NumericVector::create( 0.0, 1.0 );
    List z                   = List::create (x, y);

    return z;
}

void funcA ()
{
    std :: cout << "\nsdfsdfsdf\n";
}

int main () {return 0;}

How to place
library(RgoogleMaps)
and
png (filename="Rg.png", width=480, height=480)
inside the above code?

I run it as: R CMD SHLIB rtest.cpp

> sessionInfo()
R version 2.15.1 (2012-06-22)
Platform: x86_64-unknown-linux-gnu (64-bit)

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
 [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    
 [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
 [7] LC_PAPER=C                 LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C            
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     
> 

Rcpp's version is 0.9.13

I tried:
R CMD SHLIB -lRgoogleMaps rtest.cpp

It resulted in:

anisha@linux-y3pi:~/> R CMD SHLIB -lRgoogleMaps rtest.cpp

g++ -I/usr/lib64/R/include -DNDEBUG  -I/usr/local/include   -I/usr/lib64/R/library/Rcpp/include -fpic  -fmessage-length=0 -O2 -Wall -D_FORTIFY_SOURCE=2 -fstack-protector -funwind-tables -fasynchronous-unwind-tables  -c rtest.cpp -o rtest.o
g++ -shared -L/usr/local/lib64 -o rtest.so rtest.o -lRgoogleMaps -L/usr/lib64/R/lib -lR
/usr/lib64/gcc/x86_64-suse-linux/4.5/../../../../x86_64-suse-linux/bin/ld: cannot find -lRgoogleMaps
collect2: ld returned 1 exit status
make: *** [rtest.so] Error 1

Upvotes: 0

Views: 176

Answers (2)

Gavin Simpson
Gavin Simpson

Reputation: 174813

Why would you want to do this? Rcpp is designed for interfacing C++ code within an R session so that you can exploit faster computation or re-use existing C++ libraries.

Write an R wrapper that calls the Rcpp code, have that wrapper arrange for the package to be made available (using require(RgoogleMaps)).

Second, you don't want to hard code the plotting device. Again, you could do this in R:

png(filename="Rg.png", width=480, height=480)
##
## call Rcpp function
## in here
dev.off()

Rcpp isn't meant for writing standalone C++ applications, you still want to interact with it from an R session.

Upvotes: 3

Dirk is no longer here
Dirk is no longer here

Reputation: 368271

I think you have a bit of a conceptual problem here between what

 library(RgoogleMaps)

does in R, and what a library is for a compiler

 -lfoo -Lpath/to/library

The two are not the same, despite the fact that we use the English noun "library" in both cases.

You may need to brush up a little with a text on programming, compilers, linkers, ...

Upvotes: 5

Related Questions