Compile C Code into Win32 DLL For Use In R
Howdy All,
I asked a previous question about this and received some great help, so here we go again…
Background:
I have c code that I need to compile into a dll for use with the R programming language (http://www.r-project.org/). Using GCC in linux, everything compiled fine to a shared object and works great. Moving to the Win32 environment, I used MS VC++ to compile the code to dll with minimal changes (addtion of __declspec and include, see below).
Unix:
void samttest(double *marker, unsigned int *markercol, unsigned int *markerrow, double *label, unsigned int *labelcol, double *s0, double *tstats)
{
Function Code Here…
}
MS VC++:
#include <math.h>
__declspec (dllexport) void samttest(double *marker, unsigned int *markercol, unsigned int *markerrow, double *label, unsigned int *labelcol, double *s0, double *tstats)
{
Function Here…
}
This compiled into a usable DLL but when I load it into R, I get the following error:
DLL attempted to change FPU control word from 8001f to 9001f
This apparently is a big no-no in R. It’ll still run locally but when moved to the server, R dies. The “fixes” I’ve read told me to disable allowing FPU changes in my compiler.
Question 1–> Is that possible with VC++?
Also, I’ve tried using other compilers (Open Watcom, MinGW), Open Watcom compiles the same code as above, but when I access it in R, my PC dies. MinGW just confuses the hell out of me.
So Question 2–> How can I fix the above code so it compiles well in Open Watcom?
Question 3–> Can anyone walk me through the bases of setting up MinGW? This is the preferred compiler according to the R documentation.
My apologies for the long post but I’m at my wits end.