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
Strange problems with compiling dll
3 messages · Oleksandr Dyklevych, Romain Francois, Mike Marchywka
Hello, Your question is more appropriate on the R-devel mailing list. Le 03/12/10 00:41, Oleksandr Dyklevych a ?crit :
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
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
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
Romain Francois Professional R Enthusiast +33(0) 6 28 91 30 30 http://romainfrancois.blog.free.fr |- http://bit.ly/hovakS : RcppGSL initial release |- http://bit.ly/iaxTdO : parser 0.0-12 `- http://bit.ly/gnCl01 : Rcpp 0.8.9
----------------------------------------
Date: Fri, 3 Dec 2010 08:07:15 +0100 From: romain at r-enthusiasts.com To: r-help at r-project.org CC: diklevich at gmail.com Subject: Re: [R] Strange problems with compiling dll Hello, Your question is more appropriate on the R-devel mailing list. Le 03/12/10 00:41, Oleksandr Dyklevych a ?crit :
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.
But, when I try to compile it
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
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?...
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.
Will you help me, please, to "connect" my C compiler to R? Best regards, Oleksandr
-- Romain Francois Professional R Enthusiast +33(0) 6 28 91 30 30 http://romainfrancois.blog.free.fr |- http://bit.ly/hovakS : RcppGSL initial release |- http://bit.ly/iaxTdO : parser 0.0-12 `- http://bit.ly/gnCl01 : Rcpp 0.8.9
______________________________________________ R-help at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.