MATLAB Answers


Compiling a matlab function into a C shared .dll library

Asked by John
on 18 Jun 2013

I have 5 matlab functions that I have compiled into 5 separate shared C .dll to use with an existing software written in C. Each of these functions are independent of each other and perform a unique procedure using an instrument over VISA. In the application that I want to integrate the matlab shared libraries, the user may select from the UI which procedures to run. It may include all 5 functions, a subset of the 5, or none at all. The user may also choose to rerun any one or all of the functions.

Reading through the Compiler documentation, I found that

<lib>Terminate will bring down enough of the MCR address
space that the same library (or any other library) cannot be initialized.
Issuing a <lib>Initialize call after a <lib>Terminate call causes
unpredictable results. Instead, use the following structure:

So I am wondering what is the best practice here for loading all the libraries. Should I initialize all of them at the beginning of the application, even if I may not use all of them and terminate them all at the conclusion?

Another question is: I have a folder that contains a number of matlab functions that I either wrote myself or downloaded from FEX. The 5 functions that I am compiling separately call some of these functions. Since I am compiling each primary function separately, some of the shared functions may be compiled multiple times. This seems like bad practice. I am wondering if there is an alternative?



One other thing. I am using the instrument control toolbox in matlab to setup GPIB and VISA connections to various instruments. Each of the compiled matlab functions open and close these connections. I was wondering if there was anyway to leave them open between calling each function via mlf<lib>?

Log in to comment.

0 Answers

Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

MATLAB Academy

New to MATLAB?

Learn MATLAB today!