# Compile C Code into Win32 DLL

**URL:** <https://boards.straightdope.com/t/compile-c-code-into-win32-dll/238169>\
**Category:** Factual Questions\
**Created:** [April 4, 2004, 7:35am UTC](https://boards.straightdope.com/t/compile-c-code-into-win32-dll/238169 "2004-04-04T07:35:48Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![larsenmtl](https://avatars.discourse-cdn.com/v4/letter/l/d78d45/32.png) [@larsenmtl](https://boards.straightdope.com/u/larsenmtl)\
**Post date:** [April 4, 2004, 7:35am UTC](https://boards.straightdope.com/t/compile-c-code-into-win32-dll/238169/1 "2004-04-04T07:35:48Z")

</div>

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/](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.

---

<div class="post-metadata">

**Author:** ![Khadaji](https://avatars.discourse-cdn.com/v4/letter/k/9e8a1a/32.png) [@Khadaji](https://boards.straightdope.com/u/Khadaji)\
**Post date:** [April 4, 2004, 1:11pm UTC](https://boards.straightdope.com/t/compile-c-code-into-win32-dll/238169/2 "2004-04-04T13:11:54Z")

</div>

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](http://www.codeguru.com).

Which version of Visual Studio?

Why not use a Windows version of GCC?

---

<div class="post-metadata">

**Author:** ![larsenmtl](https://avatars.discourse-cdn.com/v4/letter/l/d78d45/32.png) [@larsenmtl](https://boards.straightdope.com/u/larsenmtl)\
**Post date:** [April 4, 2004, 8:00pm UTC](https://boards.straightdope.com/t/compile-c-code-into-win32-dll/238169/3 "2004-04-04T20:00:40Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Khadaji](https://avatars.discourse-cdn.com/v4/letter/k/9e8a1a/32.png) [@Khadaji](https://boards.straightdope.com/u/Khadaji)\
**Post date:** [April 5, 2004, 12:58pm UTC](https://boards.straightdope.com/t/compile-c-code-into-win32-dll/238169/4 "2004-04-05T12:58:02Z")

</div>

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.
