Julien Chiquet
Julien Chiquet

Reputation: 103

Prepare CRAN R package with external dependencies (nlopt)

I am trying to submit a package to CRAN that fails during the pretest process on Debian.

I use some C++ code that interfaces to the nlopt optimization library with Rcpp/RcppArmadillo (using <nlopt.hpp>). Thus, my package requires a system version of nlopt that can be installed via the deb package libnlopt-dev (I added this to the SystemRequirements field).

I use a configure script and pkg-config to retrieve the (hopefully) appropriate compiler flags which I then send to src/Makevars

NLOPT_LIBS=`pkg-config --libs ${PKG_CONFIG_NAME}`
NLOPT_FLAG=`pkg-config --cflags ${PKG_CONFIG_NAME}`

This approach works on my system (Ubuntu 18.04, R 3.5.2) and on Travis (linux and mac OS), but fails on the Debian CRAN server : https://win-builder.r-project.org/incoming_pretest/PLNmodels_0.7_20190119_161032/Debian/00install.out

I added some verbosity to check that the flags were correctly exported on CRAN servers, and they seems alright to me: at least, a version of nlopt is found on the system (see below, NLOPT_LIBS=-lnlopt -lm). However, the <nlopt.hpp> is not found latter on...

Any help would be greatly appreciated. Thank for taking the time to read this.

* installing *source* package ‘PLNmodels’ ...
Using NLOPT_LIBS=-lnlopt -lm
Using NLOPT_FLAG=
** libs
g++-8  -std=gnu++11 -I"/home/hornik/tmp/R/include" -DNDEBUG -fopenmp
-I"/home/hornik/lib/R/Library/3.6/x86_64-linux-gnu/Rcpp/include"
-I"/home/hornik/lib/R/Library/3.6/x86_64-linux-gnu/RcppArmadillo/include"
-I/usr/local/include -fopenmp  -fpic  -g -O2 -Wall -pedantic
-mtune=native -c RcppExports.cpp -o RcppExports.o
g++-8  -std=gnu++11 -I"/home/hornik/tmp/R/include" -DNDEBUG -fopenmp
-I"/home/hornik/lib/R/Library/3.6/x86_64-linux-gnu/Rcpp/include"
-I"/home/hornik/lib/R/Library/3.6/x86_64-linux-gnu/RcppArmadillo/include"
-I/usr/local/include -fopenmp  -fpic  -g -O2 -Wall -pedantic
-mtune=native -c call_nlopt_PLN_VE.cpp -o call_nlopt_PLN_VE.o
In file included from call_nlopt_PLN_VE.cpp:6:
utils.h:5:10: fatal error: nlopt.hpp: No such file or directory
 #include <nlopt.hpp>
          ^~~~~~~~~~~
compilation terminated.
make: *** [/home/hornik/tmp/R/etc/Makeconf:173: call_nlopt_PLN_VE.o] Error 1
ERROR: compilation failed for package ‘PLNmodels’
* removing ‘/srv/hornik/tmp/CRAN/PLNmodels.Rcheck/PLNmodels’

Upvotes: 4

Views: 395

Answers (2)

Dirk is no longer here
Dirk is no longer here

Reputation: 368419

You asked the same question here on r-package-devel and I had no good answer for you.

In essence, you have fine variation within one required upstream package. That is very delicate. I cannot think of anything but what @Ralf suggested: test for it.

Or maybe you just fail in communicating the requirements of your package to CRAN. But that would be an even simpler question, and when the wrong version is encountered, you are bound to fail installation.

So overall, my recommendation is the same as previously: work with Jelmer, and wait for him to release an updated nloptr release. Until then, all solutions are bound to be fudges as you cannot control what version of nloptr your package may encounter.

Upvotes: 3

Ralf Stubner
Ralf Stubner

Reputation: 26833

The C++ interface for nlopt has migrated to a separate package in Debian, c.f. https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=855600. So it looks like that particular CRAN machine uses either Debian Testing or Stable + Backports and has only libnlopt-dev but not libnlopt-cxx-dev installed. You will have to contact the CRAN maintainers to install this dependency.

BTW, ideally such errors should be cought in the configure script, i.e. you should try to compile a simple program that requires nlopt.hpp.

Upvotes: 3

Related Questions