I am new to R package development. I am developing a package (bartpkg) that has in its src/
folder one (prime) cpp file and some helper cpp (X.Cpp
, Y.Cpp
) and one c file (Z.C
) and their header files (X.h
, Y.h
and Z.h
)
I am getting the following error when I do 'Build & Reload' in Rstudio.
Error in dyn.load(dllfile) :
unable to load shared object '/Users/abcd/BART/bart_pkg1/src/bartpkg.so':
dlopen(/Users/abcd/BART/bart_pkg1/src/bartpkg.so, 6): Symbol not found: __ZN3RNG4nfixElm
Referenced from: /Users/abcd/BART/bart_pkg1/src/bartpkg.so
Expected in: flat namespace
in /Users/abcd/BART/bart_pkg1/src/bartpkg.so
Calls: suppressPackageStartupMessages ... <Anonymous> -> load_all -> load_dll -> library.dynam2 -> dyn.load
Execution halted
Exited with status 1.
I have followed the basic guidelines to build the package.
The .R file has directive #' @useDynLib bartpkg
in the right place.
Also, the prime cpp file has the following tags in the right place.
#include <Rcpp.h>
using namespace Rcpp;
//' @param x A single integer.
//' @export
// [[Rcpp::export]]
And my NAMESPACE
file shows useDynLib(bartpkg)
correctly.
I am able to see the bartpkg.so
shared object file in the src/
directory.
I tried in the terminal this command c++filt -n _ZN3RNG4nfixElm
and was able to see that the symbol in the error
Symbol not found: __ZN3RNG4nfixElm' is coming from the .C file RNG.C and is because of a function 'nfix'.
But even if I remove the function 'nfix' or remove the RNG.C
file altogether, the same error:
Symbol not found: __ZN3RNG4nfixElm
can it be a flag issue that my compiler is not able to compile the 'C' file? I am able to see that all the cpp files generate respective object files, but I dont see anything like that for the C file.
I have a Makevars
in the src/
directory just having one line
PKG_LIBS = `$(R_HOME)/bin/Rscript -e "Rcpp:::LdFlags()"`
which I basically just copied from another package, more because my understanding with Rcpp and the which flags to work with is really less.
I am using RStudio is the session info is
> sessionInfo()
R version 3.3.1 (2016-06-21)
Platform: x86_64-apple-darwin13.4.0 (64-bit)
Running under: OS X 10.11.6 (El Capitan)
locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] bartpkg_0.1.0 packrat_0.4.8-1 Rcpp_0.12.8 msm_1.6.4 LaplacesDemon_16.0.1
loaded via a namespace (and not attached):
[1] roxygen2_5.0.1 lattice_0.20-34 mvtnorm_1.0-5 digest_0.6.10 grid_3.3.1 magrittr_1.5
[7] stringi_1.1.2 Matrix_1.2-7.1 splines_3.3.1 tools_3.3.1 stringr_1.1.0 survival_2.39-5
[13] parallel_3.3.1 rsconnect_0.5 inline_0.3.14 expm_0.999-0
I am stuck at this problem for weeks now. Trying to read the 'Writing the R extension' page and not able to figure this out. Any help would be highly appreciated.
Thank you.
compileAttributes()
if you add/remove/change interface or else yourRcppExport.cpp
will be out of sync and can give such errors. – SchenckPKG_LIBS = ....
anymore. That changes a few years ago. See whatRcpp.package.skeleton()
creates for you. – SchenckRcpp::compileAttributes()
for me, so I needn't do it myself. Also, regarding your second reply, I did not create the pacakge with the help of Rcpp.Package.skeleton. I created it manually. > Any suggestions? – BurkaRcpp.package.skeleton()
or the File -> NewProject -> Package -> PackageWithRcpp option in RStudio. – Schenckextern "C"
. – Schenck