Guaner
Guaner

Reputation: 41

How to interface with a DLL in R?

I created dll extensions from Matlab. Then, I want to read that dll in R.

I used dyn.load() but it does not works.

May you give me some suggestion?

Upvotes: 4

Views: 4006

Answers (3)

Dirk is no longer here
Dirk is no longer here

Reputation: 368271

What language was the source code written in?

The trouble is mixing compilers. The Matlab dll is likely to have been built by Visual Studio. And you simply cannot mix C++ code between different compilers as function identifiers get mangled. You can, with some work, mix C object code. There are some FAQ on the MinGW site.

Upvotes: 2

Ben Bolker
Ben Bolker

Reputation: 226332

Based on the discussion in the comment thread below @Mario's answer: I was going to suggest you try the comparison you did (R CMD SHLIB dll vs Matlab dll) to help diagnose the problem. Based on the result, I think that you need to figure out what the calling syntax for the dll would be in C and write a small C wrapper for it that uses that syntax but is in turn R CMD SHLIB-able ... R CMD SHLIB --help says you can include linker options on the command line (i.e. making sure that you are linking your Matlab-callable dll with your R-callable dll), but I'm not sure of the precise syntax. It would probably help to study relevant section of the R Extensions manual a bit.

Upvotes: 1

Mario
Mario

Reputation: 1851

Some more information is necessary. The regular way to do it is like this:

dyn.load("/path/to/library");

Some pointers:

  • make sure that the architecture of the library is correct (e.g. 'x86_64' vs 'i386' vs 'armv7')
  • make sure that you're not trying to load a windows '.dll' on unix-based machines ('.so', '.dylib')

Upvotes: 0

Related Questions