How do I persuade MEX to link to a static library?

I am trying to compile a C++ file that calls some functions in a static library (.lib). I am using:
mex cfile.cpp -llibname
I get an error "LNK2019: unresolved external symbol function_name referenced in function mexFunction" for each function I call from the library, exactly as if I'd not passed mex the library file.
The .lib file links fine outside of MATLAB, e.g. when compiling an exe using cl. How do I make mex recognise the library file?

 Respuesta aceptada

Paul Bays
Paul Bays el 25 de Jun. de 2015

0 votos

I solved it. The library was 32-bit but my compiler was 64-bit.

Más respuestas (1)

Adam
Adam el 24 de Jun. de 2015
I use the
-Llibfolder
option too when I compile my mex file against a static library. It sounds as though it just isn't finding the static library. As far as I can remember the library must be in the folder in which you call the mex function if you do not specify a path.
I have a function that wraps up the mex compilation code for mine and the library being linked against is in a different folder to that function so the -L option locates it.

1 comentario

Paul Bays
Paul Bays el 24 de Jun. de 2015
I should have said I'm using -L. to tell it the .lib is in the same folder. If I don't it gives a "could not find the library" error. So, no that's not the solution.

Iniciar sesión para comentar.

Categorías

Más información sobre Write C Functions Callable from MATLAB (MEX Files) en Centro de ayuda y File Exchange.

Productos

Etiquetas

Preguntada:

el 24 de Jun. de 2015

Respondida:

el 25 de Jun. de 2015

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by