Compiling shared libraries on Windows (32 bit and 64 bit systems)

While playing with the Borg R-wrapper, I ran into difficulties loading the shared borg.dll library into R as a result of mingw compiling for a 32-bit system when I was using the 64 bit version of R.  After running the following command from the Windows command line,


gcc -shared -O3 -o borg.dll borg.c mt19937ar.c -lm

I compiled a .dll file that worked fine for the python wrapper because I have a 32 bit version of Python and the 32 bit version of the R GUI but resulted in error messages when I tried to optimize a problem using Borg in RStudio.  I was able to resolve this issue by installing MinGW-w64 and selecting the x86_64 architecture option as shown in the following screenshot.


Then, I added the following to my Windows path:

C:\Program Files\mingw-w64\x86_64-4.9.2-posix-seh-rt_v3-rev1\mingw64\bin

and ran the following command.  After this, everything ran smoothly with the Borg R wrapper.

x86_64-w64-mingw32-gcc -shared -O3 -o borg.dll borg.c mt19937ar.c -lm 

I found the following site useful for appropriate commands to compile using MinGW-w64.

One thought on “Compiling shared libraries on Windows (32 bit and 64 bit systems)

  1. Pingback: Water Programming Blog Guide (Part I) – Water Programming: A Collaborative Research Blog

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s