3

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.

  • Do you have your C code in the `src` directory of your package or just the dll? – cdeterman Dec 04 '14 at 17:12
  • Actually I have only the c code, I thought I understood that, for portability reasons, I didn't have to compile the c code before, 'cause otherwise the dll should be OK only for my own OS... Or am I wrong? – user2960323 Dec 04 '14 at 21:08
  • You are correct, interesting that the check gives those errors if build works fine. Given that you intend to submit to CRAN, would you be willing to have this put up on github? It would be easier to troubleshoot if we can look at your package structure and files like the NAMESPACE. – cdeterman Dec 05 '14 at 14:14
  • Thanks for you help cdeterman, actually 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. – user2960323 Dec 05 '14 at 14:37
  • 1
    Glad you solved your problem. You should put it below as an answer and accept it when you can so others know the problem is solved. – cdeterman Dec 05 '14 at 14:38

1 Answers1

1

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).