I'd need some help with building a Rcpp package linking to the NLopt library (http://ab-initio.mit.edu/wiki/index.php/NLopt).
I'm on Windows and using RStudio's 'Build & Reload'.
I've the following files in \src folder of the package:
- \src
- Makevars.in
- Makevars.win
- RcppExports.cpp
- nlopt.h
- nlopt.hpp
- libnlopt.lib
- libnlopt.def
- libnlopt.a
- libnlopt.dll
where I've copied the .lib (built using MinGW) and dll files of NLOpt 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 from RStudio, I get the following error message that, I suppose, tells me that there is a problem with linking (cf. "undefined reference") to the NLop library:
installing to library 'C:/Users/g49128/Documents/R/win-library/3.2'
installing source package 'NewPackage' ... ** libs
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 Rcpp_project_test.o:Rcpp_project_test.cpp:(.text+0x73c): undefined reference to `__imp_nlopt_create'
So I suspect that I haven't got the Makevars right, not so well versed in those.
From consulting several CRAN packages, in particular nloptr, my current best guess on the content of both Makevars files is:
NLOPT_HOME = c:/Temp/R/Rcpp/NewPackage/src.
KG_CFLAGS = -I"$(NLOPT_HOME)"
PKG_LIBS = -L"$(NLOPT_HOME)/libnlopt.a"
where 'libnlopt.a' is the library and the environment variable 'NLOPT_HOME' holds the path to the library.
Could anyone tell me what I'm missing here? Any help would be much appreciated, thank you.
-land-Lin Makevars (-Lis for directories-lis for lib files) - Mathieu