[Rcpp-devel] NLopt linking problem

Jens Johannsen jenschr.johannsen at gmail.com
Tue Apr 26 17:50:42 CEST 2016


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> 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).
>
> 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
>
> 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
> | https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel
>
> --
> http://dirk.eddelbuettel.com | @eddelbuettel | edd at debian.org
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20160426/a8c68f63/attachment-0001.html>


More information about the Rcpp-devel mailing list