[Rd] Compiling 64bit static library for Windows (Rtools33, MSYS2, cross-compile on linux)

Jeroen Ooms
Sat, 30 May 2015 14:07:22 -0000

Hi Sue,

I maintain a few static libs for R packages on
https://github.com/rwinlib. If your R packages are open source I can
try to add the libraries you need. Answers inline:

>    Can Rtools33 be used to compile static libraries as a separate step
>    using -m64 flag?

Yes, but usually you'll need msys to as well to run configure, etc.

>    MSYS2 is very convenient for compiling many of these libraries. Can a
>    static library compiled with x86_64-w64-mingw32 (gcc 4.9.2) be used with
>    Rtools33 (v 4.6.2)?

Sometimes. It will not work for c++ libraries because the gcc build
included with msys2 uses a different exception and threading models.
For C libraries, sometimes building in msys2 leads the static library
to depend on certain system libraries that are included with msys2 but
not with rtools.

>    Can a static library compiled using x86_64-w64-mingw32-gcc
>    cross-compiler (v 4.6.2) on linux be used with Rtools33?

If the library is built properly, this is usually not a problem; most
builds do not depend on a particular gcc version. For example static
and dynamic libraries for libcurl and dependencies (openssl, libssh2,
libz, etc) are available via http://curl.haxx.se/gknw.net/7.40.0/ and
in my experience these can be linked with any somewhat recent version
of gcc.