[Rcpp-devel] NLopt linking problem

Balamuta, James Joseph balamut2 at illinois.edu
Tue Apr 26 18:04:08 CEST 2016


Greetings and Salutations,

Try setting the environment variable NLOPT_HOME with the location of the NLopt library and then add to the Makevars.win file:

PKG_CFLAGS = -I"$(NLOPT_HOME)$(R_ARCH)/include"
PKG_LIBS = -L"$(NLOPT_HOME)$(R_ARCH)/lib" -lnlopt_cxx

Sincerely,

JJB

From: rcpp-devel-bounces at lists.r-forge.r-project.org [mailto:rcpp-devel-bounces at lists.r-forge.r-project.org] On Behalf Of Jens Johannsen
Sent: Tuesday, April 26, 2016 10:51 AM
To: Dirk Eddelbuettel <edd at debian.org>
Cc: rcpp-devel at lists.r-forge.r-project.org
Subject: Re: [Rcpp-devel] NLopt linking problem

Hi Dirk,

Thanks for the quick reply.

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.

Thanks,
Jens Christian

On Tue, Apr 26, 2016 at 5:35 PM, Dirk Eddelbuettel <edd at debian.org<mailto:edd at debian.org>> wrote:

Jens,

On 26 April 2016 at 17:22, Jens Johannsen wrote:
| Dear Rcpp-Devels, List,
|
| I'm struggling with building a Rcpp package linking to the NLopt library (http:
| //ab-initio.mit.edu/wiki/index.php/NLopt<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=>).

Before we get any further, is there a reason you are NOT using the CRAN
package doing this for you (and where I helped some with the build system):

    https://cloud.r-project.org/web/packages/nloptr/index.html<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=>

It provides a Windows binary as well as well-working build recipe as can be
expected from a CRAN package.

Dirk

| I'm on Windows and I've the following files in \src:
|
|   • Makevars.in
|   • Makevars.win
|   • Rcpp_project_test.cpp
|   • RcppExports.cpp
|   • nlopt.h
|   • nlopt.hpp
|   • libnlopt-0.lib
|   • libnlopt-0.def
|   • libnlopt-0.a
|   • libnlopt-0.dll
|
| 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.
|
| When running 'Build&Reload' from RStudio, I get the following error message
| telling me that there is a problem with linking (cf. "undefined reference"):
|
| Multithreaded BLAS/LAPACK libraries detected. Using 4 cores for math
| algorithms.
| * installing to library 'C:/Users/g49128/Documents/R/win-library/3.2'
| * installing *source* package 'NewPackage' ...
| 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
| ** libs
| 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
| Rcpp_project_test.cpp:17:0: warning: "PI" redefined [enabled by default]
| C:/PROGRA~1/R/R-32~1.2/include/R_ext/Constants.h:32:0: note: this is the
| location of the previous definition
| Multithreaded BLAS/LAPACK libraries detected. Using 4 cores for math
| algorithms.
| 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
| Multithreaded BLAS/LAPACK libraries detected. Using 4 cores for math
| algorithms.
| Rcpp_project_test.o: In function `opt':
| C:\Temp\R\Rcpp\NewPackage\src/nlopt.hpp:274: undefined reference to
| `__imp_nlopt_create'
| C:\Temp\R\Rcpp\NewPackage\src/nlopt.hpp:279: undefined reference to
| `__imp_nlopt_set_munge'
| Rcpp_project_test.o: In function `~opt':
| C:\Temp\R\Rcpp\NewPackage\src/nlopt.hpp:272: undefined reference to
| `__imp_nlopt_destroy'
| C:\Temp\R\Rcpp\NewPackage\src/nlopt.hpp:272: undefined reference to
| `__imp_nlopt_destroy'
| collect2: ld returned 1 exit status
|
| 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:
|
| PKG_CPPFLAGS = -Inlopt-2_4 -g -O1
| PKG_LIBS = `$(R_HOME)/bin/Rscript -e "Rcpp:::LdFlags()"` -Llibnlopt-0.lib
|
| Could anyone tell me what I'm missing here? Any help would be much appreciated,
| thank you.
|
|  Best Regards,
| Jens Christian
|
| _______________________________________________
| Rcpp-devel mailing list
| Rcpp-devel at lists.r-forge.r-project.org<mailto:Rcpp-devel at lists.r-forge.r-project.org>
| https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel<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=>

--
http://dirk.eddelbuettel.com<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=> | @eddelbuettel | edd at debian.org<mailto:edd at debian.org>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20160426/76a0d77c/attachment.html>


More information about the Rcpp-devel mailing list