Hi, Dirk,<div><br></div><div>Sorry for delay. </div><div><br></div><div>I tried to install the R and Rtools again, and run the program again, then it works. </div><div><br></div><div>But here is some warnings, I am not sure whether this is OK in the future.</div>
<div><br></div><div><div>Compilation argument:</div><div> C:/R/Rsoft/bin/i386/R CMD SHLIB file7e446574.cpp 2> file7e446574.cpp.err.txt </div><div>g++ -I"C:/R/Rsoft/include" -I"C:/R/Rsoft/library/Rcpp/include" -O2 -Wall -c file7e446574.cpp -o file7e446574.o</div>
<div>g++ -shared -s -static-libgcc -o file7e446574.dll tmp.def file7e446574.o C:/R/Rsoft/library/Rcpp/lib/i386/libRcpp.a -LC:/R/Rsoft/bin/i386 -lR</div><div>cygwin warning:</div><div> MS-DOS style path detected: C:/R/Rsoft/etc/i386/Makeconf</div>
<div> Preferred POSIX equivalent is: /cygdrive/c/R/Rsoft/etc/i386/Makeconf</div><div> CYGWIN environment variable option "nodosfilewarning" turns off this warning.</div><div> Consult the user's guide for more details about POSIX paths:</div>
<div> <a href="http://cygwin.com/cygwin-ug-net/using.html#using-pathnames">http://cygwin.com/cygwin-ug-net/using.html#using-pathnames</a></div></div><div><br></div><div><br></div><div>Thank you very much.</div><div><br>
</div><div>Best,</div><div><br></div><div>Kent</div><div><br><br><div class="gmail_quote">On Thu, Oct 13, 2011 at 6:46 PM, Dirk Eddelbuettel <span dir="ltr"><<a href="mailto:edd@debian.org">edd@debian.org</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><div class="im"><br>
On 13 October 2011 at 18:15, Jian Kang wrote:<br>
| Thanks for your reply.<br>
|<br>
| Here is the response of 'Hello World' program:<br>
|<br>
| > src='#include <iostream><br>
| + using namespace std;<br>
| + void main()<br>
| + {<br>
| + cout << "Hello World!" << endl;<br>
| + cout << "Welcome to C++ Programming" << endl;<br>
| + }'<br>
| > <br>
| > fx <- cxxfunction(src,plugin = "Rcpp",verbose=T)<br>
<br>
</div>PBKAC -- wrong call of cxxfunction(). You can see below how the generated<br>
code does *not* include your actual function.<br>
<br>
The correct idiom is<br>
<br>
fx <- cxxfunction(signature(), body=src,plugin = "Rcpp",verbose=TRUE)<br>
<font color="#888888"><br>
Dirk<br>
</font><div><div></div><div class="h5"><br>
<br>
| >> setting environment variables: <br>
| PKG_LIBS = C:/R/Rsoft/library/Rcpp/lib/i386/libRcpp.a<br>
|<br>
| >> LinkingTo : Rcpp<br>
| CLINK_CPPFLAGS = -I"C:/R/Rsoft/library/Rcpp/include" <br>
|<br>
| >> Program source :<br>
|<br>
| 1 : <br>
| 2 : // includes from the plugin<br>
| 3 : <br>
| 4 : #include <Rcpp.h><br>
| 5 : <br>
| 6 : <br>
| 7 : #ifndef BEGIN_RCPP<br>
| 8 : #define BEGIN_RCPP<br>
| 9 : #endif<br>
| 10 : <br>
| 11 : #ifndef END_RCPP<br>
| 12 : #define END_RCPP<br>
| 13 : #endif<br>
| 14 : <br>
| 15 : using namespace Rcpp;<br>
| 16 : <br>
| 17 : <br>
| 18 : // user includes<br>
| 19 : <br>
| 20 : <br>
| 21 : // declarations<br>
| 22 : extern "C" {<br>
| 23 : SEXP file3a1c304e( ) ;<br>
| 24 : }<br>
| 25 : <br>
| 26 : // definition<br>
| 27 : <br>
| 28 : SEXP file3a1c304e( ){<br>
| 29 : BEGIN_RCPP<br>
| 30 : <br>
| 31 : END_RCPP<br>
| 32 : }<br>
| 33 : <br>
| 34 : <br>
| Compilation argument:<br>
| C:/R/Rsoft/bin/i386/R CMD SHLIB file3a1c304e.cpp 2><br>
| file3a1c304e.cpp.err.txt <br>
| g++ -I"C:/R/Rsoft/include" -I"C:/R/Rsoft/library/Rcpp/include" -O2<br>
| -Wall -c file3a1c304e.cpp -o file3a1c304e.o<br>
| g++ -shared -s -static-libgcc -o file3a1c304e.dll tmp.def file3a1c304e.o C:/R/<br>
| Rsoft/library/Rcpp/lib/i386/libRcpp.a -LC:/R/Rsoft/bin/i386 -lR<br>
| cygwin warning:<br>
| MS-DOS style path detected: C:/R/Rsoft/etc/i386/Makeconf<br>
| Preferred POSIX equivalent is: /cygdrive/c/R/Rsoft/etc/i386/Makeconf<br>
| CYGWIN environment variable option "nodosfilewarning" turns off this<br>
| warning.<br>
| Consult the user's guide for more details about POSIX paths:<br>
| <a href="http://cygwin.com/cygwin-ug-net/using.html#using-pathnames" target="_blank">http://cygwin.com/cygwin-ug-net/using.html#using-pathnames</a><br>
| Error in as.function.default(c(value, if (is.null(bd) || is.list(bd)) list(bd)<br>
| else bd), : <br>
| invalid formal argument list for "function"<br>
|<br>
| Here, I also tried the test by Hadley,<br>
|<br>
| _devel()<br>
| cygwin warning:<br>
| MS-DOS style path detected: C:/R/Rsoft/etc/i386/Makeconf<br>
| Preferred POSIX equivalent is: /cygdrive/c/R/Rsoft/etc/i386/Makeconf<br>
| CYGWIN environment variable option "nodosfilewarning" turns off this<br>
| warning.<br>
| Consult the user's guide for more details about POSIX paths:<br>
| <a href="http://cygwin.com/cygwin-ug-net/using.html#using-pathnames" target="_blank">http://cygwin.com/cygwin-ug-net/using.html#using-pathnames</a><br>
| gcc -I"C:/R/Rsoft/include" -I"C:/R/Rsoft/library/Rcpp/include" -O3<br>
| -Wall -std=gnu99 -c foo.c -o foo.o<br>
| gcc -shared -s -static-libgcc -o foo.dll tmp.def foo.o C:/R/Rsoft/library/Rcpp/<br>
| lib/i386/libRcpp.a -LC:/R/Rsoft/bin/i386 -lR<br>
| [1] TRUE<br>
|<br>
| Sorry that I don't really get it how to rebuild R packages from source.<br>
|<br>
| Thanks,<br>
|<br>
| Kent<br>
|<br>
| On Thu, Oct 13, 2011 at 5:11 PM, Hadley Wickham <<a href="mailto:hadley@rice.edu">hadley@rice.edu</a>> wrote:<br>
|<br>
| > My best guess is that you have not installed the Rtools correctly. Can<br>
| you<br>
| > compile a simple 'hello, world' example in C or C++? Can you rebuild R<br>
| > packages from source?<br>
|<br>
| I wrote an function to check that you have a valid R development<br>
| environment (with help from Simon Urbanek) for devtools. See code<br>
| below - and check with has_devel()<br>
|<br>
| Hadley<br>
|<br>
|<br>
| has_devel <- function() {<br>
| foo_path <- file.path(tempdir(), "foo.c")<br>
|<br>
| cat("void foo(int *bar) { *bar=1; }\n", file = foo_path)<br>
| on.exit(unlink(foo_path))<br>
|<br>
| R("CMD SHLIB foo.c", tempdir())<br>
| dylib <- file.path(tempdir(), paste("foo", .Platform$dynlib.ext, sep=''))<br>
| on.exit(unlink(dylib), add = TRUE)<br>
|<br>
| dyn.load(dylib)<br>
| on.exit(dyn.unload(dylib), add = TRUE)<br>
|<br>
| stopifnot(do.call(".C", list("foo",0L))[[1]] == 1L)<br>
| TRUE<br>
| }<br>
|<br>
| R <- function(options, path = tempdir()) {<br>
| r_path <- shQuote(file.path(R.home("bin"), "R"))<br>
| in_dir(path, system_check(paste(r_path, options)))<br>
| }<br>
|<br>
| system_check <- function(cmd) {<br>
| res <- system(cmd)<br>
| if (res != 0) {<br>
| stop("Command failed (", res, ")", call. = FALSE)<br>
| }<br>
| invisible(TRUE)<br>
| }<br>
|<br>
| in_dir <- function(dir, code) {<br>
| cur <- getwd()<br>
| setwd(dir)<br>
| on.exit(setwd(cur))<br>
|<br>
| force(code)<br>
| }<br>
|<br>
| --<br>
| Assistant Professor / Dobelman Family Junior Chair<br>
| Department of Statistics / Rice University<br>
| <a href="http://had.co.nz/" target="_blank">http://had.co.nz/</a><br>
| _______________________________________________<br>
| Rcpp-devel mailing list<br>
| <a href="mailto:Rcpp-devel@lists.r-forge.r-project.org">Rcpp-devel@lists.r-forge.r-project.org</a><br>
| <a href="https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel" target="_blank">https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel</a><br>
|<br>
|<br>
<br>
</div></div><div><div></div><div class="h5">--<br>
"Outside of a dog, a book is a man's best friend. Inside of a dog, it is too<br>
dark to read." -- Groucho Marx<br>
</div></div></blockquote></div><br></div>