[Rd] R-loadable dll with minGW-compiled linked library

From: Ilana Lichtenstein <lani.lichtenstein_at_gmail.com>
Date: Tue, 30 Aug 2011 02:25:35 +1000


I am trying to create a dynamic library (dll) for loading into R with dyn.load command.

I am trying to use the library libdai (a machine learning C++ library) and boost (C++ libraries) in my main C++ program. While I am able to compile the main C++ file I am using successfully into a dll, there is a problem linking to libraries (libdai.a) and boost libraries. I only have instructions on how to compile these libraries with cygwin - NOT with minGW tools, as required by Rtools and R for correct dll creation and loading.

Currently I have R CMD SHLIB configured as follows:

(To create object file)

<path to Rtools/minGW/bin>/g++ -c -Wno-deprecated -Wall -W -Wextra -DCYGWIN -O3 -I<path toibdai/include> -I<path to boost_1_46_1> -o example.o

(To create shared library)

example examples/example.cpp
<path to Rtools/minGW/bin>/g++ -shared -s static-libgcc -o example.dll example.o -L.../libdai/lib -ldai -L"C:/cygwin/lib" -lcygwin

Including the -lcygwin library is necessary for compilation without linker error. However, it causes dyn.load to "hang" when used in R.

The tutorials on the web regarding creation of C++ dlls do not discuss linking to libraries.

Thus my two questions are:
(1) Does anyone know how to compile a C++ program which links to a library,
which dyn.load will accept? What flags are required in the R makeconf? How
do you link in a library to the dll? What flags must I compile the libdai and boost libraries with?
(2) If my interfacing issue cannot be resolved, does anyone know any tools
that interface to R that do machine learning belief propagation?

Any help is appreciated.

Ilana Lichtenstein
PhD Candidate
School of IT
University of Sydney

        [[alternative HTML version deleted]]



R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Mon 29 Aug 2011 - 16:58:47 GMT

This quarter's messages: by month, or sorted: [ by date ] [ by thread ] [ by subject ] [ by author ]

All messages

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Mon 29 Aug 2011 - 19:00:24 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.

list of date sections of archive