Linking MATLAB to a DLL library

前端 未结 5 1054
滥情空心
滥情空心 2021-01-03 04:51

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

相关标签:
5条回答
  • 2021-01-03 05:09

    The Shared Libraries cannot be used directly. As you have mentioned, you need to load them into MATLAB using loadlibrary. According to the documentation, loadlibrary takes two arguments (at least). The first argument is the name of the file, and the second one is the header file which contains definition of functions and external variables. If you do not provide the header file, the MATLAB looks for the a file with the same name as the DLL. Having said that, you need to have access to the header file or at least if you know how the function looks like, you need to write a header for the DLL.

    I have worked with the DLLs in MATLAB. The MATLAB is not very user-friendly as long as DLL is concerned. Especially, if the DLL is written in a language other than C (or C++) you will have trouble loading the function into MATLAB.

    Besides, MATLAB can only support some specific DLLs. Based, on your version of MATLAB, you need to find out whether or not the shared library is supported by MATLAB. Have a look at Here

    In a nutshell, it is not easy to load a DLL into MATLAB. You need to have some information from DLL.

    0 讨论(0)
  • 2021-01-03 05:15

    I took a look at your OSC Toolkit. It seems they have been compiled by MATLAB mex. But, it is not mentioned for which kind of architecture they have been built. You can type mexext at MATLAB command prompt to find the extension for your MATLAB mex files. Then, change the DLL extensions to the given extension. If the original mex is compatible with your matlab, the DLL can be easily accessed by MATLAB. Just make sure to add the folder to your MATLAB path.

    0 讨论(0)
  • 2021-01-03 05:19

    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,

    0 讨论(0)
  • 2021-01-03 05:23

    Try changing the extension from .dll to .mexw32 (in win32), or .wexw64 (in win64). It's a long shot but it might work.

    0 讨论(0)
  • If you look at the build for that software, it is compiling mex files, not DLLs (shared libraries): http://sourceforge.net/p/oscmex/code/4/tree/trunk/src/osc_make.m.

    I would try using the mex commands instead of the dll commands (perhaps the files are just misnamed.) Even better, I would compile the files yourself with mex using the build file in source.

    Note that the instructions also say that you need liblo-0.22 in order to run the library, so make sure you have that accessible as well.

    0 讨论(0)
提交回复
热议问题