Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Building R package with C code, dll missing

Tags:

c

package

r

dll

I'm trying to build an R package which is calling some C subroutines via .Call.

All of the functions are working fine if I manually do R CMD SHLIB and then dyn.load the .dll files.

Now, I'm building the package with R CMD build.

I put all the C code in the src folder, together with the .h files for some libraries I'm adding. When I run R CMD build NAMEPACKAGE everything seems to be fine, but then when I run R CMD check NAMEPACKAGE I get the following errors:

*** arch - i386
Error in library.dynam(lib, package, package.lib) : 
  DLL 'NAMEFUNC' not found: maybe not installed for this architecture?
Error: loading failed
Execution halted
*** arch - x64
Error in library.dynam(lib, package, package.lib) : 
  DLL 'NAMEFUNC' not found: maybe not installed for this architecture?
Error: loading failed
Execution halted
ERROR: loading failed for 'i386', 'x64'

I was trying to get some information on the internet, I have the feeling that I should write a Makevars file, but honestly I spent a lot of time on the Writing R extensions tutorial (1.2.1) and I'm really struggling to understand what is it exactly that I need to do. Could someone please beifly explain to me how to solve the problem? Consider I would like to submit my package to CRAN. Thanks.

like image 855
user2960323 Avatar asked Mar 08 '26 09:03

user2960323


1 Answers

I just found out what the problem was! It was (as usual) a fairly silly thing, I didn't know that even if you call a certain function with a certain name, the associated dll is automatically called with the name of the package and not of the function itself, like it happens instead when you just create your dll through R CMD SHLIB. Therefore, in the NAMESPACE I had to add useDynLib(NAMEOFPACKAGE) instead of useDynLib(NAMEOFFUNCTION).

like image 197
user2960323 Avatar answered Mar 10 '26 01:03

user2960323



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!