将MATLAB链接到DLL库 [英] Linking MATLAB to a DLL library

查看:117
本文介绍了将MATLAB链接到DLL库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从MATLAB工具包 oscmex 中执行一些示例代码。该工具包允许通过MATLAB使用OSC协议进行通信。我假设这个问题是非特定的;它应该适用于以这种方式设置的任何工具包。



除了原因之外,我有一些简单导致工具包启动和运行的麻烦。该工具包没有任何文件;只有一组六个DLL文件(在一个目录中),以及一组四个MATLAB'.m'示例代码文件(在另一个目录中)。我过去使用过的每一个工具包都是内置的工具包,或者是直观的(半自动化)安装程序。



下载工具包后,我尝试的第一件事是简单地运行'.M'示例代码。这个代码的第一行包含了没有(当前)MATLAB识别的函数osc()。



所以,我想也许我需要将'.M'文件移动到与DLL相同的文件夹中;也许MATLAB会看到DLL内的函数。没有骰子。



所以,我意识到,我必须以某种方式将MATLAB链接到启动时的DLL。我尝试将DLL添加到一个文件夹,并在pathdef.m文件中添加一个条目。这也失败了。



我已经读过某个地方可以使用 loadlibrary()功能加载DLL文件。所以,我尝试这样做的DLL文件。在第一个文件中失败:

 >> loadlibrary('osc_free_address.dll')

使用loadlibrary的错误> lFullPath(行587)
找不到文件osc_free_address.h。

我开始用尽选项...如何获取这组DLL并运行?

解决方案

浏览此库的网页看来,这些DLL似乎只是旧表单 -and-fortran-programs-to-be-callable-from-matlab-mex-files.htmlrel =nofollow noreferrer> mex 文件。

因此,他们应该在共享库的上下文中使用(例如,使用 loadlibrary calllib ),但是而是直接编译为mex文件。



为此,我建议以下步骤:


  1. 确保你有一个工作的mex编译器为您的Matlab配置。

    在matlab中,键入:

     >> mex -setup 

    这将引导您完成配置过程。我知道你正在使用Windows机器,我通常使用visual studio编译器,最适合我。


  2. 这个库的README文件表明OSC


    需要liblo 0.22或更高版本。请参阅 http://plugin.org.uk/liblo/


    确保你有这个库,它位于你 LD_LIBRARY_PATH (参见例如此问题,或 mex docs ) p>


  3. 源代码 4 / tree / trunk / src /rel =nofollow noreferrer>他们的存储库


  4. 使用

    在matlab中编译源>

     >> mex -O -largeArrayDims osc_free_address.c 
    >>对于所有7 c源文件,mex -O -largeArrayDims osc_free_server.c

    等等。在填写c文件后,您将拥有可从Matlab运行的mex文件,就像它们是常规功能一样。

    您可能会发现使用图书馆的make文件


祝你好运,


I am trying to execute some example code from a MATLAB toolkit, 'oscmex'. This toolkit allows for communication using the OSC protocol over MATLAB. I presume this question is non-specific; it should apply to any toolkit that is set-up in the manner that this one is.

Reasons aside, I'm having some simple trouble getting the toolkit up and running. The toolkit comes with no documentation whatsoever; just a set of six DLL files (in one directory), and a set of four MATLAB '.m' example code files (in another directory). Every toolkit I've used in the past has either been a built-in kit or has had an intuitive (semi-automated) install procedure.

After downloading the toolkit, the first thing I tried was to simply run one of the '.M' example codes. This failed as the first line of the code contained the function osc(), which is not (currently) recognised by MATLAB.

So, I figured maybe I need to move the '.M' files into the same folder as the DLLs; perhaps MATLAB would see the functions inside the DLLs. No dice.

So, I realise that I have to somehow link MATLAB to the DLLs on startup. I tried adding the DLLs to a folder and adding an entry to that in the 'pathdef.m' file. This also failed.

I've read somewhere I can load a DLL file by using the loadlibrary() function. So, I tried doing this for the DLL files. This failed on the first file:

>> loadlibrary('osc_free_address.dll')

Error using loadlibrary>lFullPath (line 587)
Could not find file osc_free_address.h.

I'm starting to run out of options... How can I get this set of DLLs up and running?

解决方案

Browsing this library's web page it would seems these DLLs are just old form of mex files.
Therefore, they should not be used in the context of shared library (e.g., using loadlibrary and calllib), but rather compiled directly to mex files.

To do so, I would suggest the following steps:

  1. Make sure you have a working mex compiler configured for your Matlab.
    In matlab, type:

    >> mex -setup
    

    this will guide you through the configuration process. I understand that you are working on a windows machine, I usually work with visual studio compiler - works best for me.

  2. This library's README file suggests that OSC

    requires liblo 0.22 or later. See http://plugin.org.uk/liblo/

    Make sure you have this library and it is located in you LD_LIBRARY_PATH (see e.g., this question for details, or the mex docs).

  3. Get the source code for OSC library from their repository.

  4. Compile the sources in matlab using

    >> mex -O -largeArrayDims osc_free_address.c
    >> mex -O -largeArrayDims osc_free_server.c
    

    and so on for all 7 c source files. After mex-ing the c files you'll have mex files that you can run from Matlab as if they were regular functions.
    You may find it useful to use the library's make file, as suggested by Andrew Mao.

Good luck,

这篇关于将MATLAB链接到DLL库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆