<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
{font-family:"Cambria Math";
panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0in;
margin-bottom:.0001pt;
font-size:12.0pt;
font-family:"Times New Roman",serif;}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:blue;
text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
{mso-style-priority:99;
color:purple;
text-decoration:underline;}
p.msonormal0, li.msonormal0, div.msonormal0
{mso-style-name:msonormal;
mso-margin-top-alt:auto;
margin-right:0in;
mso-margin-bottom-alt:auto;
margin-left:0in;
font-size:12.0pt;
font-family:"Times New Roman",serif;}
span.hoenzb
{mso-style-name:hoenzb;}
span.EmailStyle19
{mso-style-type:personal-reply;
font-family:"Calibri",sans-serif;
color:windowtext;}
.MsoChpDefault
{mso-style-type:export-only;}
@page WordSection1
{size:8.5in 11.0in;
margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
{page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-US" link="blue" vlink="purple">
<div class="WordSection1">
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif">Greetings and Salutations,<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif">Try setting the environment variable NLOPT_HOME with the location of the NLopt library and then add to the Makevars.win file:<br>
<br>
PKG_CFLAGS = -I"$(NLOPT_HOME)$(R_ARCH)/include"<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif">PKG_LIBS = -L"$(NLOPT_HOME)$(R_ARCH)/lib" -lnlopt_cxx<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif">Sincerely,<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif">JJB<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif"><o:p> </o:p></span></p>
<p class="MsoNormal"><b><span style="font-size:11.0pt;font-family:"Calibri",sans-serif">From:</span></b><span style="font-size:11.0pt;font-family:"Calibri",sans-serif"> rcpp-devel-bounces@lists.r-forge.r-project.org [mailto:rcpp-devel-bounces@lists.r-forge.r-project.org]
<b>On Behalf Of </b>Jens Johannsen<br>
<b>Sent:</b> Tuesday, April 26, 2016 10:51 AM<br>
<b>To:</b> Dirk Eddelbuettel <edd@debian.org><br>
<b>Cc:</b> rcpp-devel@lists.r-forge.r-project.org<br>
<b>Subject:</b> Re: [Rcpp-devel] NLopt linking problem<o:p></o:p></span></p>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<div>
<p class="MsoNormal">Hi Dirk,<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">Thanks for the quick reply.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">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.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">Thanks,<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">Jens Christian<o:p></o:p></p>
</div>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<p class="MsoNormal">On Tue, Apr 26, 2016 at 5:35 PM, Dirk Eddelbuettel <<a href="mailto:edd@debian.org" target="_blank">edd@debian.org</a>> wrote:<o:p></o:p></p>
<blockquote style="border:none;border-left:solid #CCCCCC 1.0pt;padding:0in 0in 0in 6.0pt;margin-left:4.8pt;margin-right:0in">
<p class="MsoNormal"><br>
Jens,<br>
<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="https://urldefense.proofpoint.com/v2/url?u=http-3A__ab-2Dinitio.mit.edu_wiki_index.php_NLopt&d=CwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=Oj62bnDE1oueLU-seL9f0p1xxu4Hvw2JDuP8BUw91c8&m=Kslm48s_EwLVJBzC5qgoDWO8bTbErDxQIYb_roS6syI&s=Lc-fmqxVj7pwXmSMXykAMQhhfyfRk-r3m-g-TbSZXyg&e=" target="_blank">ab-initio.mit.edu/wiki/index.php/NLopt</a>).<br>
<br>
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://urldefense.proofpoint.com/v2/url?u=https-3A__cloud.r-2Dproject.org_web_packages_nloptr_index.html&d=CwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=Oj62bnDE1oueLU-seL9f0p1xxu4Hvw2JDuP8BUw91c8&m=Kslm48s_EwLVJBzC5qgoDWO8bTbErDxQIYb_roS6syI&s=ojhDBjOhO36RRHphCKdAqG7i7fq5Lf5Oy1O5cIH5W-Y&e=" target="_blank">
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<o:p></o:p></p>
<div>
<div>
<p class="MsoNormal"><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>
|<o:p></o:p></p>
</div>
</div>
<p class="MsoNormal">| _______________________________________________<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://urldefense.proofpoint.com/v2/url?u=https-3A__lists.r-2Dforge.r-2Dproject.org_cgi-2Dbin_mailman_listinfo_rcpp-2Ddevel&d=CwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=Oj62bnDE1oueLU-seL9f0p1xxu4Hvw2JDuP8BUw91c8&m=Kslm48s_EwLVJBzC5qgoDWO8bTbErDxQIYb_roS6syI&s=z4lTlL2gRw2LoL-cINeiG-anIdq8yt5iBEa1u6iZZaI&e=" target="_blank">
https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel</a><br>
<span style="color:#888888"><br>
<span class="hoenzb">--</span><br>
<span class="hoenzb"><a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__dirk.eddelbuettel.com&d=CwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=Oj62bnDE1oueLU-seL9f0p1xxu4Hvw2JDuP8BUw91c8&m=Kslm48s_EwLVJBzC5qgoDWO8bTbErDxQIYb_roS6syI&s=VJacNi1uoXc5BugKBCFIMxnfv4q7DrvR5W3W4V_ePH4&e=" target="_blank">http://dirk.eddelbuettel.com</a>
| @eddelbuettel | <a href="mailto:edd@debian.org">edd@debian.org</a></span></span><o:p></o:p></p>
</blockquote>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
</div>
</body>
</html>