1

I am creating an R package called CVOC. It includes C++ code and uses high precision arithmetic from the C library gmp.

The package is to be created by the following steps:

1) using Rcpp::Rcpp.package.skeleton to create the package skeleton.

2) copying the required files, such as DESCRIPTION, NAMESPACE, Makevars, etc. , into the correct folders

3) creating the .Rd documentation files using roxygen2::roxygenise()

4) checking the R-package using R CMD check

5) building the R-package using R CMD build

When I run R CMD check "CVOC" the following error message comes up:

* installing *source* package ‘CVOC’ ...
** libs
g++ -std=c++11 -I/usr/share/R/include -DNDEBUG   -I"/home/fabian/R/x86_64-pc-linux-gnu-library/3.2/Rcpp/include" -I"/home/fabian/R/x86_64-pc-linux-gnu-library/3.2/RcppMP/include" -I"/home/fabian/R/x86_64-pc-linux-gnu-library/3.2/BH/include"   -fpic  -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g -c RcppExports.cpp -o RcppExports.o
g++ -std=c++11 -I/usr/share/R/include -DNDEBUG   -I"/home/fabian/R/x86_64-pc-linux-gnu-library/3.2/Rcpp/include" -I"/home/fabian/R/x86_64-pc-linux-gnu-library/3.2/RcppMP/include" -I"/home/fabian/R/x86_64-pc-linux-gnu-library/3.2/BH/include"   -fpic  -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g -c etcND.cpp -o etcND.o
g++ -std=c++11 -shared -L/usr/lib/R/lib -Wl,-Bsymbolic-functions -Wl,-z,relro -o CVOC.so RcppExports.o etcND.o -L/usr/lib/R/lib -lR
installing to /home/fabian/Desktop/CVOCcreate/CVOC.Rcheck/CVOC/libs
** R
** preparing package for lazy loading
** help
*** installing help indices
** building package indices
** testing if installed package can be loaded
Error in dyn.load(file, DLLpath = DLLpath, ...) : 
unable to load shared object '/home/fabian/Desktop/CVOCcreat/CVOC.Rcheck  /CVOC/libs/CVOC.so':
  /home/fabian/Desktop/CVOCcreate/CVOC.Rcheck/CVOC/libs/CVOC.so:            
undefined symbol: __gmp_bits_per_limb
Error: loading failed
Execution halted
ERROR: loading failed
* removing ‘/home/fabian/Desktop/CVOCcreate/CVOC.Rcheck/CVOC’

All the necessary files including the bash script createCVOC.sh can be found on the github repository at https://github.com/SchroederFabian/CVOC.

Any help is much appreciated.

1 Answers1

4

Something is not right, so let us check. You kindly provide a link to your src/Makevars which does in fact show that you have

CXXFLAGS= -lgmpxx -lgmp 

yet in the log you show in your question no such linking takes place:

g++ -std=c++11 -shared -L/usr/lib/R/lib -Wl,-Bsymbolic-functions \
   -Wl,-z,relro -o CVOC.so RcppExports.o etcND.o -L/usr/lib/R/lib -lR

In essence you confused

  • the PKG_* variants which allow you to "add" to existing rules with the plain ones (ie for compilation you want PKG_CXXFLAGS) and

  • you used PKG_CXXFLAGS when you needed PKG_LIBS.

Try adding

PKG_LIBS= -lgmpxx -lgmp 

and try again. Check what linking step happens. You should have the required libraries added, and no longer suffer from 'unknown symbol'.

Dirk Eddelbuettel
  • 360,940
  • 56
  • 644
  • 725
  • Thank you for pointing that out. I have changed the line in the Makevars file to PKG_LIBS = -lgmpxx -lgmp, as you suggested, but no matter what I do the flags in the log don't change. The same error 'unknown symbol' appears. – fabianschroeder Jan 12 '17 at 10:16
  • Your comment led me to realize that I had copied the Makevars file into the root folder instead of the src folder. It seems to work now. Thank you! – fabianschroeder Jan 12 '17 at 10:46
  • What you are doing in that GitHub repo seems ... unusual. There is no reason to re-run the skeleton function each time, or to copy the files. Just create the right layout, and commit that. Look at numerous other repositories and how they do it. Also, if the answer helps, please feel free to accept it (by clicking on the 'tick' mark only you see). – Dirk Eddelbuettel Jan 12 '17 at 11:15
  • This is my first R package, and this approach seemed the most transparent and most reproducible. As I am expecting difficulties in creating a portable package due to the difficult installation procedure of the gmp C library (especially on Windows) and the RcppMP library I wanted to dedicate the repository not the package but the creation process of the package. – fabianschroeder Jan 12 '17 at 11:41
  • Those are two distinct aspects. First, the layout. I suggest you alter that -- after all as only then will folks be able to do `remotes::install_github(...)` directly. Also [this line in your script](https://github.com/SchroederFabian/CVOC/blob/master/createCVOC.sh#L2) clearly has your paths in there and is not portable. Second, Windows. That is indeed harder. Study what the other packages using the GMP library do. Typically it is relying on an environment variable which eg Uwe Ligges on the win-builder sets. Also consider the rcpp-devel list with questions. – Dirk Eddelbuettel Jan 12 '17 at 11:46
  • Thank you for the suggestions! – fabianschroeder Jan 12 '17 at 11:49