<div dir="ltr"><div>Many thanks for your comments. <br></div><div><br></div><div>I have now set the value of the system environment variable NLOPT_HOME to the location of the NLopt library (this location is the /src folder of my package directory), and changed the Makevars.win (guess this is the only relevant Makevars file as the package will only be used on Windows) file to:</div><div><br></div><div><i>PKG_CFLAGS = -I"$(NLOPT_HOME)"</i></div><div><i>PKG_LIBS = -L"$(NLOPT_HOME)/libnlopt.a"</i></div><div><br></div><div>as James suggested, and which is also how it is done in the nloptr package that I'm able to build on my machine. </div><div><br></div><div><font size="1"><i>[ Note that the name of the library is 'libnlopt.a' and not 'lnlopt_cxx'. Furthermore, if I do this:</i></font></div><div><font size="1"><i><br></i></font></div><div><font size="1"><i>PKG_LIBS = -L"$(NLOPT_HOME)" -libnlopt.a</i></font></div><div><font size="1"><i><br></i></font></div><div><font size="1"><i>the R compiler immediately complains that it cannot find -libnlopt.a:</i></font></div><div><font size="1"><i><br></i></font></div><div><font size="1"><i>g++ -m64 -I"C:/PROGRA~1/R/R-32~1.2/include" -DNDEBUG    -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></font></div><div><font size="1"><i>g++ -m64 -shared -s -static-libgcc -o NewPackage.dll tmp.def RcppExports.o Rcpp_project_test.o -Lc:/Temp/R/Rcpp/NewPackage/src -libnlopt.a -Lc:/applications/extsoft/lib/x64 -Lc:/applications/extsoft/lib -LC:/PROGRA~1/R/R-32~1.2/bin/x64 -lR</i></font></div><div><font size="1"><i>c:/program files/rtools/gcc-4.6.3/bin/../lib/gcc/i686-w64-mingw32/4.6.3/../../../../i686-w64-mingw32/bin/ld.exe: cannot find -libnlopt.a ]</i></font></div><div><br></div><div>In Rcpp_project_test.cpp, I remember to include the headers nlopt.hpp and nlopt.h. And the .cpp file runs fine when using it with the Visual Studio tools. </div><div><br></div><div>Despite this, however, I still cannot link to the library. I get the following error:<br></div><div><i><br></i></div><div><i>g++ -m64 -shared -s -static-libgcc -o NewPackage.dll tmp.def RcppExports.o Rcpp_project_test.o -Lc:/Temp/R/Rcpp/NewPackage/src/libnlopt.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>Rcpp_project_test.o:Rcpp_project_test.cpp:(.text+0x73c): undefined reference to `__imp_nlopt_create'</i></div><div><br></div><div>Thus, the linking to the static library nlopt that I created (using the instructions given here: <a href="http://ab-initio.mit.edu/wiki/index.php/NLopt_on_Windows">http://ab-initio.mit.edu/wiki/index.php/NLopt_on_Windows</a>) still does not work.</div><div>I have a feeling that this is something quite simple to do, but I just cannot figure it out. </div><div><br></div><div>Any further suggestion to what I can do to fix this issue?</div><div><br></div><div>Thanks,</div><div>Best Regards,</div><div><br></div><div>Jens Christian  </div></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Apr 26, 2016 at 6:23 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>
Hi Jens,<br>
<span class=""><br>
On 26 April 2016 at 17:50, Jens Johannsen wrote:<br>
| I'm aware of the nloptr CRAN package, but not using that package as the<br>
| objective function (and gradient) being optimized as to be in C++. Defining the<br>
| function in R and then calling back and forth between R  and C++ using the<br>
| nloptr package is too costly time-wise.<br>
<br>
</span>That's not the point I was trying to make.  My point was that _the package<br>
shows how to build on all supported platforms_ and hence provides an<br>
"existence proof". So you should download _it_ and see if you can build it.<br>
You should be able too---and then be able to carry what it does over to your<br>
project.<br>
<br>
And as James said by now too, it may be as simple as setting the required env<br>
var.<br>
<br>
Cheers, Dirk<br>
<div class="HOEnZb"><div class="h5"><br>
--<br>
<a href="http://dirk.eddelbuettel.com" rel="noreferrer" target="_blank">http://dirk.eddelbuettel.com</a> | @eddelbuettel | <a href="mailto:edd@debian.org">edd@debian.org</a><br>
</div></div></blockquote></div><br></div>