开发者

How to interface with a DLL in R?

开发者 https://www.devze.com 2023-03-16 03:57 出处:网络
I created dll extensions from Matlab. Then, I want to read that dll in R开发者_StackOverflow社区.

I created dll extensions from Matlab. Then, I want to read that dll in R开发者_StackOverflow社区.

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

May you give me some suggestion?


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.


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.


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')
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号