Using Matlab functions in Visual C

Using Matlab functions in Visual C

Post by Lisa McCan » Wed, 25 Oct 2006 19:09:55

Hi there,

Could someone please help me, I am attempting to call functions in my
shared library - which was created using the Matlab compiler - from
my MSVC program.

I get the following error when I call any of the library functions;

error C2065: 'mlfFunc' : undeclared identifier

I have included the header file in my program and changed the project
settings to link the library to the program.

Any help would be great, I have been having trouble with this for a
while now,
Thank you, Lisa

Using Matlab functions in Visual C

Post by Lisa » Wed, 25 Oct 2006 23:56:00

Can anyone help me??


Using Matlab functions in Visual C

Post by John Reill » Sun, 29 Oct 2006 00:46:11

Hi Lisa,

I'm pretty sure I can help you, but you haven't given me a lot to
work from.

You used the MATLAB Compiler to compile an m-file into a DLL? And
then you're trying to call the function from C (or C++)?

C2065 is a compiler error. It usually means that you haven't
included the proper header (.h) file in your calling source file.
You can either include the proper header, or just declare the
external function in your source (for example):

extern void mlfFunc(int x, double y);

bottom line, the compiler doesn't know what the symbol mlfFunc is.
You need to tell it. Later on, when you get to the linker, you may
have other issues.

If mlfFunc is exported (i.e. publicly available in the DLL) as a C
function, and you are writing a C++ program, you need to make sure
that you declare the function as:

extern "C" { extern void mlfFunc(...); }

Otherwise the C++ compiler "mangles" (or decorates) the name and
looks for something like "mlfFunc@@2wzq", which doesn't exist.

I can go on for hours. Let me know if any of that helps.