Delen via


Building ZeroMQ package for R (rzmq) from source

rzmq (ZeroMQ for R) is available only in source form on CRAN for Windows platform. So its upto you to build and install it as a binary package. Here are few steps to help achieve that.

First, you need to get the dependencies (ZeroMQ library and MikTex) ready. ZeroMQ, as usual, can be downloaded from here, and MikTex from here. In case you opt for MikTex portable, you might need to add the MikTex bin path to the system path (i.e. pdflatex.exeprogram from the MikTex bin directory should be accessible at the command prompt). In case you are on a 64-bit machine, then you might need to install both 32-bit and 64-bit versions of the ZeroMQ libraries to ensure your package build succeeds. By default, the R build command tries to build for all platforms.

Also, you would need to download the zmq.hpp file (from here) and put it in the ZeroMQ include directory. Otherwise, you will get compiler error.

Very importantly you would need the RTools to build R packages from source. Get the RTools from here. Ensure you select the path adjustments recommended by the installer. It is VERY important that the RTools bin directory comes before the rest of your path. Otherwise there is a good chance that you will never get it to work.

After setting the dependencies, get the latest rzmq source from git here (the one on CRAN is very old - do not use it, use the git version directly) and extract it to some directory on your disk. Lets say you extract it to C:\ , then you have C:\rzmq\src\interface.cpp file that need to be compiled.

  • First, open your Visual Studio command prompt and go to your extraction folder where rzmq folder is present. In our example it is C:\

  • Now if you issue the command R CMD check rzmq you should see some output, and perhaps some build error.

    • If you get "Warning: 'rzmq' is neither a file nor directory, skipping" error, then you are not in the right directory. Go to correct directory that has rzmq folder inside it and issue the command again
    • R commands are case-sensitive, so ensure you type CMD check exactly as is
    • If you get unknown command or invalid command error, ensure that your R installation is accessible from command line. You might want to add your R bin path to your system path.
  • Build error might happen due to ZeroMQ libraries not being found. This can be fixed by modifying the Makevars file in the rzmq/src folder. The Makevars file lets you supply the additional include paths, library paths and library files required for building the C++ programs as R package. You need to set the PKG_LIBS and PKG_CPPFLAGSvariables correctly. Typically it should read,

    • PKG_LIBS = -L"C:\Program Files\ZeroMQ 2.2.0\lib" -llibzmq-v100-mt
    • PKG_CPPFLAGS=-I"C:\Program Files\ZeroMQ 2.2.0\include"

    You should specify your ZeroMq library path and header-file locations as above. The libzmq-v100-mt is the .lib file that is present in the C:\Program Files\ZeroMQ 2.2.0\lib. Note the -l before the libzmq-v100-mt.

  • Now you need to copy all dll files from ZeroMQ bin directory to to the rzmq/srcfolder.

    • For example, copy C:\Program Files\ZeroMQ 2.2.0\bin\*.dll c:\rzmq\src\
  • Issue the command R CMD check rzmq again. It should complete fine.

    • You might have to add the pdfLatex.exe path to your system path
    • Your MikTex distribution might be missing couple of packages and you might be prompted for installing them.
  • If everything is completed successfully, you should have a rzmq.RCheck folder alongside your rzmq folder with rzmq-manual.pdf built inside it correctly.

  • Now use the command R CMD INSTALL rzmq to install the built R package to your R libraries repository.

    • You can use the --library option with the R CMD INSTALL to specify an alternate R library location, if required

You should now be ready to use rzmq from your R.

On 64-bit machines, instead of the above indicated, you want to use the below --no-multiarch version commands:

    R --arch x64 CMD check --no-multiarch rzmq

    R --arch x64 CMD INSTALL --no-multiarch rzmq

Comments

  • Anonymous
    April 11, 2014
    very useful post, and the only one I've found on how to compile a r package with zmq.