GithubHelp home page GithubHelp logo

cross-swigr's Introduction

Cross-compiling R extensions for windows using MinGW and swig from linux

It is quite painful to compile R extensions on windows, so here is an example of cross-compiling a simple example for windows from linux

Pre-requisites:

  • MinGW packages in synaptic
  • mingw-w64-tools (needed for gendef)

Setup before running script

  • Install wine
  • Install R into your wine installation using the graphical installer
  • Install swig (might want to build from source, the one in default repos is quite old)

The build.sh script in this repo has the contents summarized below

N.B., you'll have to change the paths, everything is hardcoded here

N.B., By default mingw builds a 32-bit dll, which can be changed by setting -m64 compiler flag to get 64-bit build if desired. Paths should of course also be updated.

  • Generate the swig wrapper code in example_wrap.c
swig -r example.i
  • Generate a .def file with the exports from the windows DLL
gendef "/home/ian/.wine/drive_c/Program Files/R/R-3.1.3/bin/i386/R.dll" - > exports.def
  • Build an import library for the R DLL using dlltool
i686-w64-mingw32-dlltool -d exports.def -l libR.a
  • Finally, compile everything into a windows DLL
i686-w64-mingw32-gcc example_wrap.c example.c -I"/home/ian/.wine/drive_c/Program Files/R/R-3.1.3/include/" -L. -lR -shared -o example.dll
  • Once that is all done, you can run the test script in wine
wine "/home/ian/.wine/drive_c/Program Files/R/R-3.1.3/bin/i386/R.exe" -f runme.R

I found that running the script made the stdin of the console stop working for some reason. Closing the console seemed the only solution

cross-swigr's People

Contributors

ibell avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.