<div dir="ltr">Dear Rcpp-Devels, List,<div><br></div><div>I'm struggling with building a Rcpp package linking to the NLopt library (<i style="color:rgb(0,0,0);white-space:pre-wrap"><a href="http://ab-initio.mit.edu/wiki/index.php/NLopt">http://ab-initio.mit.edu/wiki/index.php/NLopt</a></i>).</div><div><br></div><div>I'm on Windows and I've the following files in \src:</div><div><ul><li>Makevars.in</li><li>Makevars.win</li><li>Rcpp_project_test.cpp</li><li>RcppExports.cpp</li><li>nlopt.h</li><li>nlopt.hpp</li><li>libnlopt-0.lib</li><li>libnlopt-0.def</li><li>libnlopt-0.a</li><li>libnlopt-0.dll</li></ul></div><div>where I've copied the .lib (built using MinGW) and dll files to the src folder in the hope that R would compile them itself. That doesn't seem to be the case, however, and for that reason I've added a Makevars file where I try to link to the library. </div><div><br></div><div>When running 'Build&Reload' from RStudio, I get the following error message telling me that there is a problem with linking (cf. "undefined reference"):</div><div><br></div><div><div><i>Multithreaded BLAS/LAPACK libraries detected. Using 4 cores for math algorithms.</i></div><div><i>* installing to library 'C:/Users/g49128/Documents/R/win-library/3.2'</i></div><div><i>* installing *source* package 'NewPackage' ...</i></div><div><i>g++ -m64 -I"C:/PROGRA~1/R/R-32~1.2/include" -DNDEBUG -Inlopt-2_4 -g -O1    -I"C:/Users/g49128/Documents/R/win-library/3.2/Rcpp/include" -I"c:/applications/extsoft/include"     -O2 -Wall  -mtune=core2 -c RcppExports.cpp -o RcppExports.o</i></div><div><i>** libs</i></div><div><i>g++ -m64 -I"C:/PROGRA~1/R/R-32~1.2/include" -DNDEBUG -Inlopt-2_4 -g -O1    -I"C:/Users/g49128/Documents/R/win-library/3.2/Rcpp/include" -I"c:/applications/extsoft/include"     -O2 -Wall  -mtune=core2 -c Rcpp_project_test.cpp -o Rcpp_project_test.o</i></div><div><i>Rcpp_project_test.cpp:17:0: warning: "PI" redefined [enabled by default]</i></div><div><i>C:/PROGRA~1/R/R-32~1.2/include/R_ext/Constants.h:32:0: note: this is the location of the previous definition</i></div><div><i>Multithreaded BLAS/LAPACK libraries detected. Using 4 cores for math algorithms.</i></div><div><i>g++ -m64 -shared -s -static-libgcc -o NewPackage.dll tmp.def RcppExports.o Rcpp_project_test.o -Lnlopt-2_4/libnlopt-0.a -Lc:/applications/extsoft/lib/x64 -Lc:/applications/extsoft/lib -LC:/PROGRA~1/R/R-32~1.2/bin/x64 -lR</i></div><div><i>Multithreaded BLAS/LAPACK libraries detected. Using 4 cores for math algorithms.</i></div><div><i>Rcpp_project_test.o: In function `opt':</i></div><div><i>C:\Temp\R\Rcpp\NewPackage\src/nlopt.hpp:274: undefined reference to `__imp_nlopt_create'</i></div><div><i>C:\Temp\R\Rcpp\NewPackage\src/nlopt.hpp:279: undefined reference to `__imp_nlopt_set_munge'</i></div><div><i>Rcpp_project_test.o: In function `~opt':</i></div><div><i>C:\Temp\R\Rcpp\NewPackage\src/nlopt.hpp:272: undefined reference to `__imp_nlopt_destroy'</i></div><div><i>C:\Temp\R\Rcpp\NewPackage\src/nlopt.hpp:272: undefined reference to `__imp_nlopt_destroy'</i></div><div><i>collect2: ld returned 1 exit status</i></div></div><div><br></div><div>I suspect that I haven't got the Makevars right, not so well versed in those. From reading several CRAN packages, in particular nloptr, my current best guess on the content of both Makevars files is:</div><div><br></div><div><div><i>PKG_CPPFLAGS = -Inlopt-2_4 -g -O1 </i></div><div><i>PKG_LIBS = `$(R_HOME)/bin/Rscript -e "Rcpp:::LdFlags()"` -Llibnlopt-0.lib</i></div></div><div><br></div><div>Could anyone tell me what I'm missing here? Any help would be much appreciated, thank you.</div><div><br></div><div> Best Regards,</div><div>Jens Christian</div><div><div><br></div></div></div>