Skip to content

Strange problems with compiling dll

3 messages · Oleksandr Dyklevych, Romain Francois, Mike Marchywka

#
Dear sir\madam!

I'm trying to speed up my R code by writing quite simple dll's in C. But I  
faced some problems, and I cannot determine their source.

#include <Rinternals.h>

SEXP mycombin(SEXP N, SEXP k){
     int i, *j, *l, c;
     j = INTEGER(k);l = INTEGER(N);
     c = 1;
     if(j[0] > 0 && j[0] < l[0]){
         if(j[0] <= l[0] - j[0]){
             for(i = l[0]; i >= l[0] - j[0] + 1; i--){
                 c = c * i / (l[0] - i + 1);
             }
         }
         else{
             for(i = l[0]; i <= j[0] + 1; i++){
                 c = c * i / (l[0] - i + 1);
             }
         }
     }
     return ScalarInteger(c);
}

But, when I try to compile it I have 5 errors, and all of them come form  
linker and say next (Code::Blocks):

||=== mcb2, Release ===|
obj\Release\conv.o:conv.c|| undefined reference to `INTEGER'|
obj\Release\conv.o:conv.c|| undefined reference to `INTEGER'|
obj\Release\conv.o:conv.c|| undefined reference to `Rf_ScalarInteger'|
obj\Release\conv.o:conv.c|| undefined reference to `Rf_ScalarInteger'|
obj\Release\conv.o:conv.c|| undefined reference to `Rf_ScalarInteger'|
||=== Build finished: 5 errors, 0 warnings ===|


I found out that I need to link Rdll.lib, but to make it I should use  
these instructions

make R.exp
lib /def:R.exp /out:Rdll.lib

but i cannot figure out where I should use them.
I'm trying from here C:\Rtools\src\gnuwin32 but each time i get
make: *** No rule to make target `R.exp'.  Stop.

So where should I state this rule and which rule?...

Will you help me, please, to "connect" my C compiler to R?

Best regards,
Oleksandr
#
Hello,

Your question is more appropriate on the R-devel mailing list.

Le 03/12/10 00:41, Oleksandr Dyklevych a ?crit :
What does that mean ? What did you try ?

R CMD SHLIB mycomin.c

definitely works for me. What part of "Writing R Extensions" was not clear ?

Romain

  
    
#
----------------------------------------
In response to this message I tried to get some background
on rtools as I'd like to do this myself but I didn't
get too far yet.

Generally with make there is something called Makefile

http://www.gnu.org/software/make/manual/make.html#Introduction

in which all the stuff is. 

Often with these things, there is a script
called "configure" which you run to test all your tools and setup any
things likely to change on various machines like paths to libs. 

If you have no idea what is going on, typing "make" with no params? 
is usually a good guess but check for a README file etc. 

Undefined linker errors of course are usually missing or incorrect libs
often due to bad paths etc.