<div> Hi Dirk,</div><div> </div><div>Thanks for you help, here is wha I got in a test package:</div><div> </div><div>1.Rcpp.package.skeleton("cpptest")</div><div>2. Add the following line to Makevars</div><div> </div><div>PKG_CPPFLAGS=-I/opt/boost_1_54_0/include -I../inst/include PKG_LIBS = -L/opt/boost_1_54_0/lib -lboost_regex `$(R_HOME)/bin/Rscript -e "Rcpp:::LdFlags()"`<br></div><div><div>3. Change  rcpp_hello_world.cpp to this:</div><div> </div><div>#include "rcpp_hello_world.h"<br>#include <boost/lambda/lambda.hpp><br>#include <boost/regex.hpp><br>#include <iostream><br>#include <iterator><br>#include <algorithm></div><div>using namespace std;<br>using namespace Rcpp;</div><div><br>int test(std::string line){</div><div> boost::regex pat("^Subject: (Re: |Aw: )*(.*)" );<br> boost::smatch matches;<br> if (boost::regex_match(line, matches, pat))<br>  return 1;<br> return 0;<br>}</div><div>SEXP rcpp_hello_world(){</div><div> std::string line1 = "Subject: (Re: I am amber";<br> std::string line2 = "Subject: (Aw: Who are you";</div><div>    <br>    NumericVector y   = NumericVector::create(test(line1), test(line2)) ;<br>    List z            = List::create( y ) ;<br>    <br>    return z ;<br>}<br></div><div>4: </div><div> </div><div>[root@cent64 dev]# R CMD INSTALL cpptest<br>* installing to library ¡®/usr/lib64/R/library¡¯<br>* installing *source* package ¡®cpptest¡¯ ...<br>** libs<br>make: Nothing to be done for `all'.<br>installing to /usr/lib64/R/library/cpptest/libs<br>** R<br>** preparing package for lazy loading<br>** help<br>Warning: /home/amber/R/dev/cpptest/man/cpptest-package.Rd:31: All text must be in a section<br>Warning: /home/amber/R/dev/cpptest/man/cpptest-package.Rd:32: All text must be in a section<br>*** installing help indices<br>  converting help for package ¡®cpptest¡¯<br>    finding HTML links ... done<br>    cpptest-package                         html  <br>    rcpp_hello_world                        html  <br>** building package indices<br>** testing if installed package can be loaded<br>Error in dyn.load(file, DLLpath = DLLpath, ...) : <br>  unable to load shared object '/usr/lib64/R/library/cpptest/libs/cpptest.so':<br>  /usr/lib64/R/library/cpptest/libs/cpptest.so: undefined symbol: _ZTIN4Rcpp7RObjectE<br>Error: loading failed<br>Execution halted<br>ERROR: loading failed<br>* removing ¡®/usr/lib64/R/library/cpptest¡¯<br>[root@cent64 dev]# exit<br></div><div>Actually, I am trying to use boost library with Rcpp, do I miss anything?</div><div> </div><div>Regards,</div><div> </div><div>Xiaobo Gu</div><div> </div><div> </div><div><br> </div><div><br></div><div style="padding: 2px 0px; font-family: Arial Narrow; font-size: 12px;">------------------ Original ------------------</div><div style="background: rgb(239, 239, 239); padding: 8px; font-size: 12px;"><div><b>From: </b> "Dirk Eddelbuettel"<edd@debian.org>;</div><div><b>Date: </b> Sep 3, 2013</div><div><b>To: </b> "guxiaobo1982"<guxiaobo1982@qq.com>; <wbr></div><div><b>Cc: </b> "rcpp-devel"<rcpp-devel@lists.r-forge.r-project.org>; <wbr></div><div><b>Subject: </b> Re: [Rcpp-devel] How to use external C++ libraries in R packages withRcpp.</div></div><div><br></div><br>Hi Xiaobo,<br><br>On 2 September 2013 at 18:33, guxiaobo1982 wrote:<br>| We are going to package an external C++ library into a R package, and I'd like<br>| to know Rcpp can help a lot,<br><br>Yes, Rcpp can help a lot in that case. <br><br>Many existing packages provides examples, starting for example with RcppGSL<br>by Romain and myself and many other existing CRAN packages which connect to<br>external libraries using Rcpp.<br><br>We have an entire vignette devoted to using Rcpp for your package:<br>Rcpp-package.  And my Rcpp book has a chapter on this too.<br><br>| but we have two sinarioes:<br><br>[ You probably meant "scenarios" ]<br><br>| 1. We have only c++ header files, .lib dynamic link file and .dll dynamic<br>| runtime library.<br><br>".lib" and ".dll" sounds a lot like Windows-only.  Please understand that you<br>generally cannot link with Visual C++-compiled code (unless you do a pure C<br>layer in between, and even that is tricky.<br><br>But any "standard" library -- such as GSL, or anything else that is portable<br>and available on Windows, Linux and OS X can be used.<br><br>| 2. A whole C++ library with all the header and .cpp source file in a seperate<br>| directory.<br><br>That can be done too; you could build a static library first. The trick is to<br>avoid having to do a custom Makefile (as R prefers you do just use<br>src/Makevars or src/Makevars.win) so sometimes it is easier to just have all<br>the files in src/* --- I helped the folks with the phylobase package do just<br>that.<br>  <br>You can hardcode Windows path in src/Makevars.win, possibly using an<br>environment variable.  Here is the one from RcppGSL:<br><br><br>  ## This assumes that the LIB_GSL variable points to working GSL libraries<br>  PKG_CPPFLAGS=-I$(LIB_GSL)/include -I../inst/include<br>  PKG_LIBS=-L$(LIB_GSL)/lib -lgsl -lgslcblas $(shell "${R_HOME}/bin${R_ARCH_BIN}/Rscript.exe" -e "Rcpp:::LdFlags()")<br><br>For Unix one often uses configure but as a first approximation you can also<br>use environment variables on src/Makevars.<br><br>| In both sinarioes, how can I specify additional include pathes, add the<br>| additional sources, and link against external .lib files.<br><br>Please see the vignette, or the chapter in my book.<br><br>Dirk<br>  <br>| Regards,<br>|  <br>| Xiaobo Gu<br>| <br>| ----------------------------------------------------------------------<br>| _______________________________________________<br>| Rcpp-devel mailing list<br>| Rcpp-devel@lists.r-forge.r-project.org<br>| https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel<br>-- <br>Dirk Eddelbuettel | edd@debian.org | http://dirk.eddelbuettel.com<br>.<br></div>