Compile C Code into Win32 DLL

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.

I’m not at work so don’t have quick access to VC help. If no one answers you I’ll try to look it up tomorrow. Also try the message boards at www.codeguru.com.

Which version of Visual Studio?

Why not use a Windows version of GCC?

Thanks for the reply, Khadaji.

I tried to install MinGW which is a WinDoze port of GCC but the install process confused the heck out of me. So, I downloaded and installed Dev-C++ which provides a GUI to MinGW and a much easier install. I compiled it using the exact same code as I used with VC++ and it compiled fine. So far no error when I tested it here at home, but I won’t know if it’s completely right until tomorrow when I can run it on the server at work.

More questions…

Anything wrong with my function declaration?
What’s the best GCC port on Windows?
Why does VC++ require me to include math.h but GCC does not?

Oh, I’m useing MS VC++ 6.0

Thanks.

I have not had a lot of luck finding information about floating point units (FPU) in Visual C++. The only reference that I have found is for support under ARM. You might try the link I provided and see if the guys and codeguru have any ideas.