MEX Compiler: How to link to libraries with .dll or .a extension (from MinGW compiler)?

33 views (last 30 days)
Hey there,
I am facing a struggle with linking a library to my mex-file. The library itself is compiled with a MinGW compiler, that is also used for the Mex-Compiler. MinGW either outputs a static library with ".a" extension or a shared library as ".dll"-file with a ".a" file to link to. When I use the -l flag with the mex command, it tells me the following:
>> mex KVM.cpp -L. -llibvehicleModelLib.a
Error using mex
MEX cannot find library 'libvehicleModelLib.a' specified with the
-l option.
MEX looks for a file with one of the names:
liblibvehicleModelLib.a.lib
libvehicleModelLib.a.lib
Please specify the path to this library with the -L option.
The Mex-Compiler obviously only looks for (MSVC-generated) .lib files. The same occurs when I try to directly link to the DLL with the -l flag. Both linking to .a and to .dll with the -l flag is possible with the underlying MinGW Compiler.
So my question is, how is it possible to tell the mex compiler to look for other library file extensions than "lib"? It is clear it would work, if the command would accept it, since the -l flag is then just handed to the underlying "g++" compiler command.
PS: I know I can link to a static .a library by using just like an object file, with out the -l flag, but this would not help for linking to a shared dll library, what would be my prefered option.
Thank you for any help! :)
  4 Comments
Darshan Ramakant Bhat
Darshan Ramakant Bhat on 2 Jul 2021
Can you please try
>> mex KVM.cpp -L. libvehicleModelLib.a
Where "libvehicleModelLib" is the actual name of the static library

Sign in to comment.

Answers (0)

Products

Community Treasure Hunt

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

Start Hunting!