Thread Subject: MEX and CLR

Subject: MEX and CLR

From: Stiphu

Date: 23 May, 2011 08:28:04

Message: 1 of 7

Hi there

I programmed a camera interface in CLR and want to implement it now into a MEX function. That works fine, I can compile it and call it from Matlab. But as far as I call a mex function as

mexPrintf("hello world \n");

for instance, I get linker errors:

1>mexFunction.obj : error LNK2028: unresolved token (0A0003CA) "extern "C" int __cdecl mexPrintf(char const *,...)" (?mexPrintf@@$$J0YAHPEBDZZ) referenced in function "extern "C" void __cdecl mexFunction(int,struct mxArray_tag * * const,int,struct mxArray_tag const * * const)" (?mexFunction@@$$J0YAXHQEAPEAUmxArray_tag@@HQEAPEBU1@@Z)
1>mexFunction.obj : error LNK2019: unresolved external symbol "extern "C" int __cdecl mexPrintf(char const *,...)" (?mexPrintf@@$$J0YAHPEBDZZ) referenced in function "extern "C" void __cdecl mexFunction(int,struct mxArray_tag * * const,int,struct mxArray_tag const * * const)" (?mexFunction@@$$J0YAXHQEAPEAUmxArray_tag@@HQEAPEBU1@@Z)

Any suggestions how to get around that?

Subject: MEX and CLR

From: Rune Allnor

Date: 23 May, 2011 09:06:29

Message: 2 of 7

On May 23, 10:28 am, "Stiphu " <schm...@pyl.unibe.ch> wrote:
> Hi there
>
> I programmed a camera interface in CLR and want to implement it now into a MEX function. That works fine, I can compile it and call it from Matlab. But as far as I call a mex function as
>
> mexPrintf("hello world \n");
>
> for instance, I get linker errors:
>
> 1>mexFunction.obj : error LNK2028: unresolved token (0A0003CA) "extern "C" int __cdecl mexPrintf(char const *,...)" (?mexPrintf@@$$J0YAHPEBDZZ) referenced in function "extern "C" void __cdecl mexFunction(int,struct mxArray_tag * * const,int,struct mxArray_tag const * * const)" (?mexFunction@@$$J0YAXHQEAPEAUmxArray_tag@@HQEAPEBU1@@Z)
> 1>mexFunction.obj : error LNK2019: unresolved external symbol "extern "C" int __cdecl mexPrintf(char const *,...)" (?mexPrintf@@$$J0YAHPEBDZZ) referenced in function "extern "C" void __cdecl mexFunction(int,struct mxArray_tag * * const,int,struct mxArray_tag const * * const)" (?mexFunction@@$$J0YAXHQEAPEAUmxArray_tag@@HQEAPEBU1@@Z)
>
> Any suggestions how to get around that?

Install your compiler / linker combo correctly.
Or, equivalently, configure it correctly for use
with MEX.

Rune

Subject: MEX and CLR

From: Stiphu

Date: 23 May, 2011 11:12:04

Message: 3 of 7

> Install your compiler / linker combo correctly.
> Or, equivalently, configure it correctly for use
> with MEX.
>
> Rune

And how can I do that, what did I do wrong?

Subject: MEX and CLR

From: Rune Allnor

Date: 23 May, 2011 11:28:05

Message: 4 of 7

On May 23, 1:12 pm, "Stiphu " <schm...@pyl.unibe.ch> wrote:
> > Install your compiler / linker combo correctly.
> > Or, equivalently, configure it correctly for use
> > with MEX.
>
> > Rune
>
> And how can I do that,

Read the docs for both the compiler and matlab.
Check if matlab provides a config file for your
compiler. If not, recreate the config file.

> what did I do wrong?

Well, I don't know what *you* did wrong, but the
error messages are rather clear to the effect that
there is a linker configuration problem.

Rune

Subject: MEX and CLR

From: Stiphu

Date: 23 May, 2011 11:29:04

Message: 5 of 7

What I forgot to mention: I'm compiling the MEX file in the Visual Studio 2010 IDE... This one works:

// Include libraries
#include "FIA_camInterface.h"
#include "mil.h"
// MEX BUG
#ifdef _CHAR16T
#define CHAR16_T
#endif
// Include Matlab header
#include "mex.h"

//#include "string.h"

void mexFunction( int nlhs, mxArray *plhs[],
                  int nrhs, const mxArray *prhs[] )
{
// Init camera
std::string DCF_PATH_s = "D:\\Fast Image Acquisition\\DCF";
FIA_videoMode videoMode("COM4", LOW_RES, DCF_PATH_s);
}

And this one causes the linker error:

// Include libraries
#include "FIA_camInterface.h"
#include "mil.h"
// MEX BUG
#ifdef _CHAR16T
#define CHAR16_T
#endif
// Include Matlab header
#include "mex.h"

//#include "string.h"

void mexFunction( int nlhs, mxArray *plhs[],
                  int nrhs, const mxArray *prhs[] )
{
// Test output
mexPrintf("hello world \n");
// Init camera
std::string DCF_PATH_s = "D:\\Fast Image Acquisition\\DCF";
FIA_videoMode videoMode("COM4", LOW_RES, DCF_PATH_s);
}

Subject: MEX and CLR

From: Rune Allnor

Date: 23 May, 2011 11:44:53

Message: 6 of 7

On May 23, 1:29 pm, "Stiphu " <schm...@pyl.unibe.ch> wrote:
> What I forgot to mention: I'm compiling the MEX file in the Visual Studio 2010 IDE... This one works:

Ok...

Try and write a minimum MEX file that only contains the line

  mexPrintf("hello world \n");

Does this work when compiled in C mode? In C++ mode? If 'no',
what version of matlab do you use?

At first glance this might have something to do with name
mangling in C++. Does your matlab vesrion support VS2010 C++?
To do that it might need a number of pre-compiled libraries.
The error messages you posted might indicate that such
copiler-specific libraries are not available.

Rune

Subject: MEX and CLR

From: Stiphu

Date: 23 May, 2011 12:23:04

Message: 7 of 7

Hi Rune

Tnx very much for the help. I configured the IDE as described here:
http://www.mathworks.com/help/techdoc/matlab_external/f24338.html#f24571

The mistake I made was under point 7 (Locate the .lib files for the compiler you are using under matlabroot\extern\lib\win32\microsoft or matlabroot\extern\lib\win64\microsoft. Under Linker Input properties, add libmx.lib, libmex.lib, and libmat.lib as additional dependencies.). I copied and pasted those 3 libraries into the folder d:\specLibs which was included in the project. But there were probably other libraries used by those included libraries, so there was no error message. Now I added the whole path under the "linker input properties", so everything works fine now!

Thanks again for your help, have a nice day
Stiphu

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
clr Stiphu 23 May, 2011 04:29:06
mex Stiphu 23 May, 2011 04:29:06
linker Stiphu 23 May, 2011 04:29:06
error Stiphu 23 May, 2011 04:29:06
rssFeed for this Thread

Contact us at files@mathworks.com