RcppCore/Rcpp

Error in R_useDynamicSymbols building custom library on windows 10

Closed this issue · 13 comments

I have a library I'm building that has had no issue running linux, but when I try to build it on windows I'm getting an error. I'm using devtools to run load_all, document, check, etc and getting the following error from the R_useDynamicSymbols line generated in RcppExports:
RcppExports.cpp: In function 'void R_init_Colossus(DllInfo*)':
RcppExports.cpp:38:30: error: invalid conversion from 'int' to 'Rboolean' [-fpermissive]
38 | R_useDynamicSymbols(dll, FALSE);

It appears to be treating the "FALSE" as an integer.

I've tried double checking my Rcpp library versions and Rtools installation, but nothing has changed. I'm getting the same error through Rstudio and RGui. I've put together a github repository that contains a shortened version of my code that is giving the same error on my system. The repository has the same dependencies as my actual library.

Is there a preferred way to install custom packages in windows that use Rcpp?

Output of sessionInfo():
R version 4.2.2 (2022-10-31 ucrt)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19045)

Matrix products: default

locale:
[1] LC_COLLATE=English_United States.utf8 LC_CTYPE=English_United States.utf8 LC_MONETARY=English_United States.utf8 LC_NUMERIC=C LC_TIME=English_United States.utf8

attached base packages:
[1] stats graphics grDevices utils datasets methods base

other attached packages:
[1] devtools_2.4.5 usethis_2.1.6

loaded via a namespace (and not attached):
[1] Rcpp_1.0.10 pillar_1.8.1 compiler_4.2.2 later_1.3.0 urlchecker_1.0.1 prettyunits_1.1.1 profvis_0.3.7 remotes_2.4.2 tools_4.2.2 testthat_3.1.6 digest_0.6.31
[12] pkgbuild_1.4.0 pkgload_1.3.2 tibble_3.1.8 lattice_0.20-45 memoise_2.0.1 lifecycle_1.0.3 pkgconfig_2.0.3 rlang_1.0.6 Matrix_1.5-3 shiny_1.7.4 cli_3.6.0
[23] rstudioapi_0.14 fastmap_1.1.1 withr_2.5.0 stringr_1.5.0 desc_1.4.2 fs_1.6.1 vctrs_0.5.2 htmlwidgets_1.6.1 grid_4.2.2 rprojroot_2.0.3 glue_1.6.2
[34] R6_2.5.1 processx_3.8.0 fansi_1.0.4 sessioninfo_1.2.2 callr_3.7.3 purrr_1.0.1 magrittr_2.0.3 ps_1.7.2 promises_1.2.0.1 ellipsis_0.3.2 htmltools_0.5.4
[45] mime_0.12 xtable_1.8-4 httpuv_1.6.9 utf8_1.2.3 stringi_1.7.12 miniUI_0.1.1.1 RcppParallel_5.1.7 cachem_1.0.7 RcppEigen_0.3.3.9.3 crayon_1.5.2 brio_1.1.3

Thanks for filing an issue. Please consider reading

  • how to format in Markdown to make your issue more legible, there are both guides and the ability to look at the underlying 'code' of existing issues
  • how to create a minimally complete and verifiable example: as we do not have your repo, we cannot help you

Rcpp has been used by thousands of people on Windows as well as other OSs for fifteen years. Your issue is likely local.

Thank you for your response. My public repo is linked in my issue, I was under the impression that it qualified as a minimally complete and verifiable example. I'm able to see and download it from a non-logged in window.

I'm getting the same error on both win-builder and R-hub, so unfortunately I don't think its just a local issue. Thank you for letting me know this isn't a previously encountered issue.

My second comment holds. Create a minimal example. As you, I and everybody else can see Rcpp has no issues on Windows either per the usual page:

image

Something I often show / suggest at the beginning of workshops is

> Rcpp::evalCpp("2 * 21")
[1] 42
> 

I presume that works for you. What happens afterwards with your package is most likely your issue. The rcpp-devel list may be a quicker route to help on Windows which I don't use -- and I think more people 'lurk' on the list than here at the repo.

Also your package, as presented in the repo, does not build for me. I just checked it out, ran compileAttributes() just in case and then get a missing symbol:

edd@rob:/tmp/rcpp/Colossus_WIN_Error(main)$ R CMD INSTALL -l ../lib .
* installing *source* package ‘Colossus’ ...
** using staged installation
** libs
ccache g++  -std=gnu++14 -I"/usr/share/R/include" -DNDEBUG  -I'/usr/local/lib/R/site-library/Rcpp/include' -I'/usr/local/lib/R/site-library/RcppEigen/include' -I'/usr/local/lib/R/site-library/RcppParallel/include' -I'/usr/local/lib/R/site-library/testthat/include'   -fopenmp -fpic  -g -O3 -Wall -pipe  -Wno-parentheses -Wno-ignored-attributes -Wno-unused-local-typedefs -Wno-deprecated-declarations -Wno-unused-function  -c R_Interface.cpp -o R_Interface.o
ccache g++  -std=gnu++14 -I"/usr/share/R/include" -DNDEBUG  -I'/usr/local/lib/R/site-library/Rcpp/include' -I'/usr/local/lib/R/site-library/RcppEigen/include' -I'/usr/local/lib/R/site-library/RcppParallel/include' -I'/usr/local/lib/R/site-library/testthat/include'   -fopenmp -fpic  -g -O3 -Wall -pipe  -Wno-parentheses -Wno-ignored-attributes -Wno-unused-local-typedefs -Wno-deprecated-declarations -Wno-unused-function  -c RcppExports.cpp -o RcppExports.o
ccache g++ -std=gnu++14 -Wl,-S -shared -L/usr/lib/R/lib -Wl,-Bsymbolic-functions -flto=auto -ffat-lto-objects -flto=auto -Wl,-z,relro -o Colossus.so R_Interface.o RcppExports.o -llapack -lblas -lgfortran -lm -lquadmath -fopenmp -L/usr/lib/R/lib -lR
installing to /tmp/rcpp/lib/00LOCK-Colossus_WIN_Error/00new/Colossus/libs
** R
** byte-compile and prepare package for lazy loading
** help
No man pages found in package  ‘Colossus’ 
*** installing help indices
** building package indices
** testing if installed package can be loaded from temporary location
Error: package or namespace load failed for ‘Colossus’ in dyn.load(file, DLLpath = DLLpath, ...):
 unable to load shared object '/tmp/rcpp/lib/00LOCK-Colossus_WIN_Error/00new/Colossus/libs/Colossus.so':
  /tmp/rcpp/lib/00LOCK-Colossus_WIN_Error/00new/Colossus/libs/Colossus.so: undefined symbol: run_testthat_tests
Error: loading failed
Execution halted
ERROR: loading failed
* removing ‘/tmp/rcpp/lib/Colossus’
edd@rob:/tmp/rcpp/Colossus_WIN_Error(main)$ 

Ball in your court.

It appears I removed too many files for the minimal example, thank you for catching that. The repo should be updated if you wanted to check it. I'll check out the rcpp-devel list. I honestly appreciate the direction. If I figure out what is going wrong, I'll come back to this thread. I'm assuming its some library or build option that I'm just completely unaware of.

The message in

has to be repeated. Your example has RcppEigen, RcppParallel, use of OpenMP, ... none of which is used. At least the latter is known-complicated. I am now running at RHub but it is of course slow as you decided to have dependencies on several boatloads of packages 🤷‍♂️

I simple threw a lot of stuff out of the really-not-minimal-at-all files in your src/ directory and after that it all build also on Windows and contrarary to your claims. See for yourself for as long as the RHub log remains up.

I will close this now. By all means please reopen if and when you have a demonstrated shortcoming. Until then, and I say that earnestly having earned all my bruises in debugging code and projects of my own, I really recommend minimising when chasing issues. It helped and many others, it may help you too.

If it helps you I can send you a PR of my locally-modified copy of your repo. Just let me know.

Correction: I was hasty above and the posted link did not lead a successful build at Windows. (I had fallen before to RHub completing but not clearly signalling it failed.)

A better and complete check result is is now here. It passes with flying colours. I removed everything but Rcpp dependencies to keep it simple. You can add things one by one from there if you want.

Thank you for your suggestion. It was the inclusion of RcppParallel. My complete code had it added in anticipation of having to use it, which I never ended up needing so I can test the complete code without it. Without it the code isn't having any issue.

There was just a recent update to RcppParallel and a new version; and something was as I recall related to TBB and threading on Windows.

The gist of it all remains though: you needlessly added extra complexity which prevented you from seeing a root cause. But glad you're sorted now.

Can you just use (Rboolean) 0; that is, cast the value?

This sort of problem occurs on Windows because some Windows headers will define their own versions of TRUE and FALSE, which collide with R's own macro definitions. See how R handles this here:

https://github.com/wch/r-source/blob/1d4b7f8e08ed9e0e8398ad7d5a7520f3839eb364/src/include/R_ext/Boolean.h#L26-L41

You could also just remove the existing TRUE and FALSE defines after all your includes.

And/or reorder header includes.