<div dir="ltr"><div>Hi Dirk,</div><div><br></div><div>Thanks for the quick reply.</div><div><br></div><div>I'm aware of the nloptr CRAN package, but not using that package as the objective function (and gradient) being optimized as to be in C++. Defining the function in R and then calling back and forth between R and C++ using the nloptr package is too costly time-wise.</div><div><br></div><div>Thanks,</div><div>Jens Christian</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Apr 26, 2016 at 5:35 PM, Dirk Eddelbuettel <span dir="ltr"><<a href="mailto:edd@debian.org" target="_blank">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"><br>
Jens,<br>
<span><br>
On 26 April 2016 at 17:22, Jens Johannsen wrote:<br>
| Dear Rcpp-Devels, List,<br>
|<br>
| I'm struggling with building a Rcpp package linking to the NLopt library (http:<br>
| //<a href="http://ab-initio.mit.edu/wiki/index.php/NLopt" target="_blank" rel="noreferrer">ab-initio.mit.edu/wiki/index.php/NLopt</a>).<br>
<br>
</span>Before we get any further, is there a reason you are NOT using the CRAN<br>
package doing this for you (and where I helped some with the build system):<br>
<br>
<a href="https://cloud.r-project.org/web/packages/nloptr/index.html" target="_blank" rel="noreferrer">https://cloud.r-project.org/web/packages/nloptr/index.html</a><br>
<br>
It provides a Windows binary as well as well-working build recipe as can be<br>
expected from a CRAN package.<br>
<br>
Dirk<br>
<div><div class="h5"><br>
| I'm on Windows and I've the following files in \src:<br>
|<br>
| • Makevars.in<br>
| • Makevars.win<br>
| • Rcpp_project_test.cpp<br>
| • RcppExports.cpp<br>
| • nlopt.h<br>
| • nlopt.hpp<br>
| • libnlopt-0.lib<br>
| • libnlopt-0.def<br>
| • libnlopt-0.a<br>
| • libnlopt-0.dll<br>
|<br>
| where I've copied the .lib (built using MinGW) and dll files to the src folder<br>
| in the hope that R would compile them itself. That doesn't seem to be the case,<br>
| however, and for that reason I've added a Makevars file where I try to link to<br>
| the library. <br>
|<br>
| When running 'Build&Reload' from RStudio, I get the following error message<br>
| telling me that there is a problem with linking (cf. "undefined reference"):<br>
|<br>
| Multithreaded BLAS/LAPACK libraries detected. Using 4 cores for math<br>
| algorithms.<br>
| * installing to library 'C:/Users/g49128/Documents/R/win-library/3.2'<br>
| * installing *source* package 'NewPackage' ...<br>
| g++ -m64 -I"C:/PROGRA~1/R/R-32~1.2/include" -DNDEBUG -Inlopt-2_4 -g -O1 <br>
| -I"C:/Users/g49128/Documents/R/win-library/3.2/Rcpp/include" -I"c:/<br>
| applications/extsoft/include" -O2 -Wall -mtune=core2 -c RcppExports.cpp -o<br>
| RcppExports.o<br>
| ** libs<br>
| g++ -m64 -I"C:/PROGRA~1/R/R-32~1.2/include" -DNDEBUG -Inlopt-2_4 -g -O1 <br>
| -I"C:/Users/g49128/Documents/R/win-library/3.2/Rcpp/include" -I"c:/<br>
| applications/extsoft/include" -O2 -Wall -mtune=core2 -c<br>
| Rcpp_project_test.cpp -o Rcpp_project_test.o<br>
| Rcpp_project_test.cpp:17:0: warning: "PI" redefined [enabled by default]<br>
| C:/PROGRA~1/R/R-32~1.2/include/R_ext/Constants.h:32:0: note: this is the<br>
| location of the previous definition<br>
| Multithreaded BLAS/LAPACK libraries detected. Using 4 cores for math<br>
| algorithms.<br>
| g++ -m64 -shared -s -static-libgcc -o NewPackage.dll tmp.def RcppExports.o<br>
| Rcpp_project_test.o -Lnlopt-2_4/libnlopt-0.a -Lc:/applications/extsoft/lib/x64<br>
| -Lc:/applications/extsoft/lib -LC:/PROGRA~1/R/R-32~1.2/bin/x64 -lR<br>
| Multithreaded BLAS/LAPACK libraries detected. Using 4 cores for math<br>
| algorithms.<br>
| Rcpp_project_test.o: In function `opt':<br>
| C:\Temp\R\Rcpp\NewPackage\src/nlopt.hpp:274: undefined reference to<br>
| `__imp_nlopt_create'<br>
| C:\Temp\R\Rcpp\NewPackage\src/nlopt.hpp:279: undefined reference to<br>
| `__imp_nlopt_set_munge'<br>
| Rcpp_project_test.o: In function `~opt':<br>
| C:\Temp\R\Rcpp\NewPackage\src/nlopt.hpp:272: undefined reference to<br>
| `__imp_nlopt_destroy'<br>
| C:\Temp\R\Rcpp\NewPackage\src/nlopt.hpp:272: undefined reference to<br>
| `__imp_nlopt_destroy'<br>
| collect2: ld returned 1 exit status<br>
|<br>
| I suspect that I haven't got the Makevars right, not so well versed in those.<br>
| From reading several CRAN packages, in particular nloptr, my current best guess<br>
| on the content of both Makevars files is:<br>
|<br>
| PKG_CPPFLAGS = -Inlopt-2_4 -g -O1 <br>
| PKG_LIBS = `$(R_HOME)/bin/Rscript -e "Rcpp:::LdFlags()"` -Llibnlopt-0.lib<br>
|<br>
| Could anyone tell me what I'm missing here? Any help would be much appreciated,<br>
| thank you.<br>
|<br>
| Best Regards,<br>
| Jens Christian<br>
|<br>
</div></div>| _______________________________________________<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" rel="noreferrer">https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel</a><br>
<span class="HOEnZb"><font color="#888888"><br>
--<br>
<a href="http://dirk.eddelbuettel.com" target="_blank" rel="noreferrer">http://dirk.eddelbuettel.com</a> | @eddelbuettel | <a href="mailto:edd@debian.org">edd@debian.org</a><br>
</font></span></blockquote></div><br></div>