[Rcpp-devel] Request for help with compiling Rcpp example

Dirk Eddelbuettel edd at debian.org
Thu Oct 13 18:46:35 CEST 2011


On 13 October 2011 at 18:15, Jian Kang wrote:
| Thanks for your reply.
| 
| Here is the response of 'Hello World' program:
| 
| > src='#include <iostream>
| + using namespace std;
| + void main()
| + {
| + cout << "Hello World!" << endl;
| + cout << "Welcome to C++ Programming" << endl;
| + }'
|| > fx <- cxxfunction(src,plugin = "Rcpp",verbose=T)

PBKAC -- wrong call of cxxfunction().  You can see below how the generated
code does *not* include your actual function.

The correct idiom is

    fx <- cxxfunction(signature(), body=src,plugin = "Rcpp",verbose=TRUE)

Dirk


|  >> setting environment variables: 
| PKG_LIBS =  C:/R/Rsoft/library/Rcpp/lib/i386/libRcpp.a
| 
|  >> LinkingTo : Rcpp
| CLINK_CPPFLAGS =  -I"C:/R/Rsoft/library/Rcpp/include" 
| 
|  >> Program source :
| 
|    1 : 
|    2 : // includes from the plugin
|    3 : 
|    4 : #include <Rcpp.h>
|    5 : 
|    6 : 
|    7 : #ifndef BEGIN_RCPP
|    8 : #define BEGIN_RCPP
|    9 : #endif
|   10 : 
|   11 : #ifndef END_RCPP
|   12 : #define END_RCPP
|   13 : #endif
|   14 : 
|   15 : using namespace Rcpp;
|   16 : 
|   17 : 
|   18 : // user includes
|   19 : 
|   20 : 
|   21 : // declarations
|   22 : extern "C" {
|   23 : SEXP file3a1c304e( ) ;
|   24 : }
|   25 : 
|   26 : // definition
|   27 : 
|   28 : SEXP file3a1c304e(  ){
|   29 : BEGIN_RCPP
|   30 : 
|   31 : END_RCPP
|   32 : }
|   33 : 
|   34 : 
| Compilation argument:
|  C:/R/Rsoft/bin/i386/R CMD SHLIB file3a1c304e.cpp 2>
| file3a1c304e.cpp.err.txt 
| g++ -I"C:/R/Rsoft/include"    -I"C:/R/Rsoft/library/Rcpp/include"      -O2
| -Wall  -c file3a1c304e.cpp -o file3a1c304e.o
| g++ -shared -s -static-libgcc -o file3a1c304e.dll tmp.def file3a1c304e.o C:/R/
| Rsoft/library/Rcpp/lib/i386/libRcpp.a -LC:/R/Rsoft/bin/i386 -lR
| cygwin warning:
|   MS-DOS style path detected: C:/R/Rsoft/etc/i386/Makeconf
|   Preferred POSIX equivalent is: /cygdrive/c/R/Rsoft/etc/i386/Makeconf
|   CYGWIN environment variable option "nodosfilewarning" turns off this
| warning.
|   Consult the user's guide for more details about POSIX paths:
|     http://cygwin.com/cygwin-ug-net/using.html#using-pathnames
| Error in as.function.default(c(value, if (is.null(bd) || is.list(bd)) list(bd)
| else bd),  : 
|   invalid formal argument list for "function"
| 
| Here, I also tried the test by Hadley,
| 
| _devel()
| cygwin warning:
|   MS-DOS style path detected: C:/R/Rsoft/etc/i386/Makeconf
|   Preferred POSIX equivalent is: /cygdrive/c/R/Rsoft/etc/i386/Makeconf
|   CYGWIN environment variable option "nodosfilewarning" turns off this
| warning.
|   Consult the user's guide for more details about POSIX paths:
|     http://cygwin.com/cygwin-ug-net/using.html#using-pathnames
| gcc -I"C:/R/Rsoft/include"    -I"C:/R/Rsoft/library/Rcpp/include"      -O3
| -Wall  -std=gnu99 -c foo.c -o foo.o
| gcc -shared -s -static-libgcc -o foo.dll tmp.def foo.o C:/R/Rsoft/library/Rcpp/
| lib/i386/libRcpp.a -LC:/R/Rsoft/bin/i386 -lR
| [1] TRUE
| 
| Sorry that I don't really get it how to rebuild R packages from source.
| 
| Thanks,
| 
| Kent
| 
| On Thu, Oct 13, 2011 at 5:11 PM, Hadley Wickham <hadley at rice.edu> wrote:
| 
|     > My best guess is that you have not installed the Rtools correctly.  Can
|     you
|     > compile a simple 'hello, world' example in C or C++?  Can you rebuild R
|     > packages from source?
| 
|     I wrote an function to check that you have a valid R development
|     environment (with help from Simon Urbanek) for devtools.  See code
|     below - and check with has_devel()
| 
|     Hadley
| 
| 
|     has_devel <- function() {
|      foo_path <- file.path(tempdir(), "foo.c")
| 
|      cat("void foo(int *bar) { *bar=1; }\n", file = foo_path)
|      on.exit(unlink(foo_path))
| 
|      R("CMD SHLIB foo.c", tempdir())
|      dylib <- file.path(tempdir(), paste("foo", .Platform$dynlib.ext, sep=''))
|      on.exit(unlink(dylib), add = TRUE)
| 
|      dyn.load(dylib)
|      on.exit(dyn.unload(dylib), add = TRUE)
| 
|      stopifnot(do.call(".C", list("foo",0L))[[1]] == 1L)
|      TRUE
|     }
| 
|     R <- function(options, path = tempdir()) {
|      r_path <- shQuote(file.path(R.home("bin"), "R"))
|      in_dir(path, system_check(paste(r_path, options)))
|     }
| 
|     system_check <- function(cmd) {
|      res <- system(cmd)
|      if (res != 0) {
|        stop("Command failed (", res, ")", call. = FALSE)
|      }
|      invisible(TRUE)
|     }
| 
|     in_dir <- function(dir, code) {
|      cur <- getwd()
|      setwd(dir)
|      on.exit(setwd(cur))
| 
|      force(code)
|     }
| 
|     --
|     Assistant Professor / Dobelman Family Junior Chair
|     Department of Statistics / Rice University
|     http://had.co.nz/
|     _______________________________________________
|     Rcpp-devel mailing list
|     Rcpp-devel at lists.r-forge.r-project.org
|     https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel
| 
| 

-- 
"Outside of a dog, a book is a man's best friend. Inside of a dog, it is too
dark to read." -- Groucho Marx


More information about the Rcpp-devel mailing list