0

I am trying to build a package but the Cpp bit is causing an error. This package is very similar to another one which also has a cpp bit and I do manage to build it without problems. I have checked usual errors like:

  • Not having the linkingTo Rccp in the DESCRIPTION as here.
  • Remove xxx.o and xxx.so files in the src/ and try to compile and also the RccpExports.R as here.
  • I tried Compile(".") and tools::package_native_routine_registration_skeleton(".") although I do not really understand what they mean...

The error

* installing to library 'C:/Program Files/R/R-3.4.0/library'
* installing *source* package 'PackageName' ...
** libs
c:/Rtools/mingw_64/bin/g++  -I"C:/PROGRA~1/R/R-34~1.0/include" -DNDEBUG  -I"C:/Program Files/R/R-3.4.0/library/Rcpp/include"   -I"d:/Compiler/gcc-4.9.3/local330/include"     -O2 -Wall  -mtune=core2 -c RcppExports.cpp -o RcppExports.o
c:/Rtools/mingw_64/bin/gcc  -I"C:/PROGRA~1/R/R-34~1.0/include" -DNDEBUG  -I"C:/Program Files/R/R-3.4.0/library/Rcpp/include"   -I"d:/Compiler/gcc-4.9.3/local330/include"     -O2 -Wall  -std=gnu99 -mtune=core2 -c init.c -o init.o
c:/Rtools/mingw_64/bin/g++  -I"C:/PROGRA~1/R/R-34~1.0/include" -DNDEBUG  -I"C:/Program Files/R/R-3.4.0/library/Rcpp/include"   -I"d:/Compiler/gcc-4.9.3/local330/include"     -O2 -Wall  -mtune=core2 -c rcpp_hello.cpp -o rcpp_hello.o
c:/Rtools/mingw_64/bin/g++ -shared -s -static-libgcc -o PackageName.dll tmp.def RcppExports.o init.o rcpp_hello.o -Ld:/Compiler/gcc-4.9.3/local330/lib/x64 -Ld:/Compiler/gcc-4.9.3/local330/lib -LC:/PROGRA~1/R/R-34~1.0/bin/x64 -lR
init.o:init.c:(.rdata+0x28): undefined reference to `PackageName_rcpp_hello'
collect2.exe: error: ld returned 1 exit status
no DLL was created
ERROR: compilation failed for package 'PackageName'
* removing 'C:/Program Files/R/R-3.4.0/library/PackageName'

Exited with status 1.

Details on my session:

R version 3.4.0 (2017-04-21)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 7 x64 (build 7601) Service Pack 1
Rstudio: 1.1.383
Rcpp: Rcpp_0.12.12
user3507584
  • 3,246
  • 5
  • 42
  • 66
  • 1
    Please run `compileAttributes()` from your package directory. – Dirk Eddelbuettel Apr 12 '18 at 16:10
  • @DirkEddelbuettel It yields nothing: compileAttributes(".") – user3507584 Apr 12 '18 at 16:17
  • 1
    That is a little odd. Are you sure `getwd()` returns the directory also containing `DESCRIPTION` and `NAMESPACE`? In any event, why don't you start with a freshly produced package using `Rcpp.package.skeleton("mypackagenamehere")`? That function is well tested. – Dirk Eddelbuettel Apr 12 '18 at 17:21
  • @DirkEddelbuettel When I run `getwd' I get the directory containing `DESCRIPTION' and `NAMESPACE'. Unfortunately I cannot start from 0 as I am joining a package started by my colleague. – user3507584 Apr 12 '18 at 17:55
  • 1
    Starting with a _temporary package_ may aid your understanding, allows you to compare, and to establish that your toolchain is correctly setup. I was not suggesting to throw your existing package away. – Dirk Eddelbuettel Apr 12 '18 at 17:58
  • @DirkEddelbuettel So you are suggesting that I start a new Rstudio package project file and test if Rcpp.package.skeleton("mypackagenamehere") works? – user3507584 Apr 12 '18 at 18:02
  • Yes. To give you a baseline. And _if_ you are in RStudio then `compileAttributes()` gets called for you anyway. You should have said that earlier. Now my guess is that you forgot to set up `NAMESPACE`. Compare with the created package, and adapt. – Dirk Eddelbuettel Apr 12 '18 at 18:07
  • 1
    1/ Using version control, can you try `usethis::use_rcpp()`? 2/ Do you include external librairies like in [this question](https://stackoverflow.com/q/38575678/6103040)? – F. Privé Apr 13 '18 at 06:17
  • @F.Privé I've got: `> use_rcpp() ✔ Adding 'Rcpp' to LinkingTo field in DESCRIPTION ✔ Setting 'Rcpp' version to * field in DESCRIPTION ✔ Adding '*.o', '*.so', '*.dll' to 'src/.gitignore' ● Include the following roxygen tags somewhere in your package Copying code to clipboard: #' @useDynLib PackageName, .registration = TRUE #' @importFrom Rcpp sourceCpp NULL ● Run document()` – user3507584 Apr 13 '18 at 09:04
  • @F.Privé I pasted the following at the end of NAMESPACE `@useDynLib USMunis, .registration = TRUE importFrom Rcpp sourceCpp NULL` The result of `devtools::document()` yields an error: `"Undefined reference to PackageName_rcpp_hello [...] No DLL was created".` – user3507584 Apr 13 '18 at 09:05
  • Is your package on GitHub? – F. Privé Apr 13 '18 at 11:02
  • @F.Privé No, it is a private package. I found the solution. There seems to be a problem between Rcpp 0.12.10 and Rcpp 0.12.12. My colleagues created a package with the 10 version and I wasn't able to build it in the 12 version. Additionally, it seems that R. 3.4.0 does not fully delete the Rcpp package in the library when I was downgrading it so a .dll file was still left there when I was reinstalling it. I had to manually delete all the files to actually downgrade the Rcpp package. – user3507584 Apr 13 '18 at 13:10
  • 1
    Sounds like it is due to the change we had to make because of R change. You need to just re-run `compileAttributes()` under the new version -- but sadly one time you need to run it twice. This has come up before, there is no elegant way to deal with it. Sorry. – Dirk Eddelbuettel Apr 13 '18 at 13:45
  • @DirkEddelbuettel The Rcpp is still a great tool. I thank you for all your great work in this and other packages! And for all your help in SO too! – user3507584 Apr 13 '18 at 14:25
  • 1
    @DirkEddelbuettel Maybe you can post an answer with the cause and many possible solutions to try so that people with the same problem can find the solution here. – F. Privé Apr 13 '18 at 15:11
  • @F.Privé This is already [Rcpp FAQ Answer 5.7](https://cran.r-project.org/web/packages/Rcpp/vignettes/Rcpp-FAQ.pdf) – Dirk Eddelbuettel Apr 13 '18 at 15:12

0 Answers0