I figured out you can just change the lib name to end '.lib' instead of '.a'. This shouldn't work since a .a file is a different structure from a .lib file, but apparently mingw-w64 is smart enough to notice the file format.
Lining to static library using Mingw-w64
14 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Richard Crozier
am 4 Jul. 2017
Kommentiert: timo
am 28 Mär. 2018
I want to create a mex file which links to a static library. This library was created using Mingw-w64 and has the .a file extension. I am also using Mingw as my mex compiler in matlab. When I attempt to build the mex file, with a command like the following (where library file is libmbc.a found in the 'H:\rnfoundry-hg\common\multibody\mbdyn_win64\include' directory):
mexMBCNodal.cpp -lmbc CXXFLAGS="$CXXFLAGS -std=c++11" -lws2_32.lib -I"H:\rnfoundry-hg\common\multibody\mbdyn_win64\include" -L"H:\rnfoundry-hg\common\multibody\mbdyn_win64\lib" -v
I get the following error:
Warning: Unable to compile mex functions mexMBCNodal. Error reported was:
MEX cannot find library 'mbc' specified with the -l option.
MEX looks for a file with one of the names:
libmbc.lib
mbc.lib
Please specify the path to this library with the -L option.
Following this I tried specifying the full path to the library, like so:
mexMBCNodal.cpp -lH:\rnfoundry-hg\common\multibody\mbdyn_win64\lib\libmbc.a CXXFLAGS="$CXXFLAGS -std=c++11" -lws2_32.lib -I"H:\rnfoundry-hg\common\multibody\mbdyn_win64\include" -v
But I then get the following error:
Warning: Unable to compile mex functions mexMBCNodal. Error reported was:
$$LIB not found; check that you are in the correct current folder, and check the spelling of '$$LIB'.
Is there any way to link to a .a library or must I create a .lib file. If so, is there a Mingw-w64 tool which can create a .lib file from a .a file?
I am using R2016b in case this is relevant.
0 Kommentare
Akzeptierte Antwort
Richard Crozier
am 6 Jul. 2017
1 Kommentar
timo
am 28 Mär. 2018
This is a horrible hack . Mingw64 uses .a for its static libraries extension and not .lib ! (.lib is for Microsoft Visual Studio libraries names) It looks like a bug
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu MATLAB Support for MinGW-w64 C/C++ Compiler finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!