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&gt; file7e446574.cpp.err.txt </div><div>g++ -I&quot;C:/R/Rsoft/include&quot;    -I&quot;C:/R/Rsoft/library/Rcpp/include&quot;      -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 &quot;nodosfilewarning&quot; turns off this warning.</div><div>  Consult the user&#39;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">&lt;<a href="mailto:edd@debian.org">edd@debian.org</a>&gt;</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 &#39;Hello World&#39; program:<br>
|<br>
| &gt; src=&#39;#include &lt;iostream&gt;<br>
| + using namespace std;<br>
| + void main()<br>
| + {<br>
| + cout &lt;&lt; &quot;Hello World!&quot; &lt;&lt; endl;<br>
| + cout &lt;&lt; &quot;Welcome to C++ Programming&quot; &lt;&lt; endl;<br>
| + }&#39;<br>
| &gt; <br>
| &gt; fx &lt;- cxxfunction(src,plugin = &quot;Rcpp&quot;,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 &lt;- cxxfunction(signature(), body=src,plugin = &quot;Rcpp&quot;,verbose=TRUE)<br>
<font color="#888888"><br>
Dirk<br>
</font><div><div></div><div class="h5"><br>
<br>
|  &gt;&gt; setting environment variables: <br>
| PKG_LIBS =  C:/R/Rsoft/library/Rcpp/lib/i386/libRcpp.a<br>
|<br>
|  &gt;&gt; LinkingTo : Rcpp<br>
| CLINK_CPPFLAGS =  -I&quot;C:/R/Rsoft/library/Rcpp/include&quot; <br>
|<br>
|  &gt;&gt; Program source :<br>
|<br>
|    1 : <br>
|    2 : // includes from the plugin<br>
|    3 : <br>
|    4 : #include &lt;Rcpp.h&gt;<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 &quot;C&quot; {<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&gt;<br>
| file3a1c304e.cpp.err.txt <br>
| g++ -I&quot;C:/R/Rsoft/include&quot;    -I&quot;C:/R/Rsoft/library/Rcpp/include&quot;      -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 &quot;nodosfilewarning&quot; turns off this<br>
| warning.<br>
|   Consult the user&#39;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 &quot;function&quot;<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 &quot;nodosfilewarning&quot; turns off this<br>
| warning.<br>
|   Consult the user&#39;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&quot;C:/R/Rsoft/include&quot;    -I&quot;C:/R/Rsoft/library/Rcpp/include&quot;      -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&#39;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 &lt;<a href="mailto:hadley@rice.edu">hadley@rice.edu</a>&gt; wrote:<br>
|<br>
|     &gt; My best guess is that you have not installed the Rtools correctly.  Can<br>
|     you<br>
|     &gt; compile a simple &#39;hello, world&#39; example in C or C++?  Can you rebuild R<br>
|     &gt; 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 &lt;- function() {<br>
|      foo_path &lt;- file.path(tempdir(), &quot;foo.c&quot;)<br>
|<br>
|      cat(&quot;void foo(int *bar) { *bar=1; }\n&quot;, file = foo_path)<br>
|      on.exit(unlink(foo_path))<br>
|<br>
|      R(&quot;CMD SHLIB foo.c&quot;, tempdir())<br>
|      dylib &lt;- file.path(tempdir(), paste(&quot;foo&quot;, .Platform$dynlib.ext, sep=&#39;&#39;))<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(&quot;.C&quot;, list(&quot;foo&quot;,0L))[[1]] == 1L)<br>
|      TRUE<br>
|     }<br>
|<br>
|     R &lt;- function(options, path = tempdir()) {<br>
|      r_path &lt;- shQuote(file.path(R.home(&quot;bin&quot;), &quot;R&quot;))<br>
|      in_dir(path, system_check(paste(r_path, options)))<br>
|     }<br>
|<br>
|     system_check &lt;- function(cmd) {<br>
|      res &lt;- system(cmd)<br>
|      if (res != 0) {<br>
|        stop(&quot;Command failed (&quot;, res, &quot;)&quot;, call. = FALSE)<br>
|      }<br>
|      invisible(TRUE)<br>
|     }<br>
|<br>
|     in_dir &lt;- function(dir, code) {<br>
|      cur &lt;- 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>
&quot;Outside of a dog, a book is a man&#39;s best friend. Inside of a dog, it is too<br>
dark to read.&quot; -- Groucho Marx<br>
</div></div></blockquote></div><br></div>