[Rcpp-devel] NLopt linking problem

Jens Johannsen jenschr.johannsen at gmail.com
Wed Apr 27 17:25:54 CEST 2016


Many thanks for your comments.

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:

*PKG_CFLAGS = -I"$(NLOPT_HOME)"*
*PKG_LIBS = -L"$(NLOPT_HOME)/libnlopt.a"*

as James suggested, and which is also how it is done in the nloptr package
that I'm able to build on my machine.

*[ Note that the name of the library is 'libnlopt.a' and not 'lnlopt_cxx'.
Furthermore, if I do this:*

*PKG_LIBS = -L"$(NLOPT_HOME)" -libnlopt.a*

*the R compiler immediately complains that it cannot find -libnlopt.a:*

*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*
*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*
*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 ]*

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.

Despite this, however, I still cannot link to the library. I get the
following error:

*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'*

Thus, the linking to the static library nlopt that I created (using the
instructions given here:
http://ab-initio.mit.edu/wiki/index.php/NLopt_on_Windows) still does not
work.
I have a feeling that this is something quite simple to do, but I just
cannot figure it out.

Any further suggestion to what I can do to fix this issue?

Thanks,
Best Regards,

Jens Christian

On Tue, Apr 26, 2016 at 6:23 PM, Dirk Eddelbuettel <edd at debian.org> wrote:

>
> Hi Jens,
>
> On 26 April 2016 at 17:50, Jens Johannsen wrote:
> | 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.
>
> That's not the point I was trying to make.  My point was that _the package
> shows how to build on all supported platforms_ and hence provides an
> "existence proof". So you should download _it_ and see if you can build it.
> You should be able too---and then be able to carry what it does over to
> your
> project.
>
> And as James said by now too, it may be as simple as setting the required
> env
> var.
>
> Cheers, Dirk
>
> --
> 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/20160427/e6ff0738/attachment.html>


More information about the Rcpp-devel mailing list