yael mex files for windows in Matlab - matlab

I have a problem in using yael library in matlab.
Yael library has some functions like yael_ivf that has written in c.
I'm using mex command in matlab to create mex file but there are some error like this -->
Error using mex Creating library yael_ivf.lib and object
yael_ivf.exp yael_ivf.obj : error LNK2019: unresolved external
symbol _ivf_new referenced in function _mexFunction yael_ivf.obj
: error LNK2019: unresolved external symbol _ivf_delete referenced
in function _mexFunction
Please help me to mex them or if link me to Yael windows mex file.
This is yael library link: gforge.inria.fr/frs/?group_id=2151 in this page there are some links to download, for mac, for linux and windows. The Yael library for linux and mac contain mex files but unfortunately there aren't any mex file in windows link.
If you download windows yael library (third link), in matlab folder, when you run make.m, mex files must create. but there are some errors for me.

Related

Why does my code fail to buld with Mex but work with cl?

Hey so I'm working to attach a piece of hardware into a setup controlled with MATLAB. I've written a set of functions (tried both C and C++) that utilize this hardware to perform simple tasks.
The code compiles just fine using cl. When I try to compile with mex however, it cannot seem to link symbols from my includes (am using the -I flag pointing to directory of my header files).
Any thoughts?
CL Output:
>cl isConnected.c *.lib
Microsoft (R) C/C++ Optimizing Compiler Version 19.28.29334 for x86
Copyright (C) Microsoft Corporation. All rights reserved.
isConnected.c
Microsoft (R) Incremental Linker Version 14.28.29334.0
Copyright (C) Microsoft Corporation. All rights reserved.
/out:isConnected.exe
isConnected.obj
ArenaCd_v140.lib
ArenaC_v140.lib
isConnectedMex.lib
SaveCd_v140.lib
SaveC_v140.lib
MATLAB Output:
>> curDir = pwd;
>> linkPath = ['-L' fullfile(curDir,'\lib64\ArenaC\ArenaC_v140.lib')];
>> incPath = ['-I' fullfile(curDir,'\include\ArenaC')];
>> exist(linkPath(3:end))
ans = 2
>> exist(incPath(3:end))
ans = 7
>> % Paths Are Correctly named it seems
>> mex('isConnectedMex.c',incPath,linkPath)
Building with 'Microsoft Visual C++ 2019 (C)'.
Error using mex
Creating library isConnectedMex.lib and object isConnectedMex.exp
isConnectedMex.obj : error LNK2019: unresolved external symbol __imp_acOpenSystem referenced in function main
isConnectedMex.obj : error LNK2019: unresolved external symbol __imp_acGetLastErrorMessage referenced in function main
isConnectedMex.obj : error LNK2019: unresolved external symbol __imp_acSystemUpdateDevices referenced in function main
isConnectedMex.obj : error LNK2019: unresolved external symbol __imp_acSystemGetNumDevices referenced in function main
isConnectedMex.mexw64 : fatal error LNK1120: 4 unresolved externals
The functions referenced by MATLAB errors are #include in one of my headers. Using -v option with MEX though it shows these folders are being included. Any help would be greatly appreciated!!
Edit: Adding cl and mex commands used. The only difference between isConnected.c and isConnectedMex.c is that isConnectedMex.c uses the mexFunction call as it's main method.
The -L option is to specify a directory where the linker can find required library files. You need to use the -l option (lowercase L) to specify which libraries to link. This is what it looks like:
mex isConnectedMex.c -Iinclude\ArenaC -Llib64\ArenaC -lArenaC_v140
Or, if the lib file is a static library, you can pass it as an input file:
mex isConnectedMex.c lib64\ArenaC\ArenaC_v140.lib -Iinclude\ArenaC

Link to gfortran for mex file

I am trying to create mex files for using some C++ code in Matlab, but running into an error with the compilation which, I guess, goes beyond Matlab. I am on Windows.
The example I'm struggling with is the Mex Interface example in the Armadillo library for linear algebra, available: here. The Matlab file is what I'm running and it looks like this:
% Compile the demo as a mex file
mex -lgfortran armaMex_demo.cpp -I/path/to/armadillo
The error I get is:
Error using mex
MEX cannot find library 'gfortran' specified with the -l option.
MEX looks for a file with one of the names:
libgfortran.lib
gfortran.lib
Please specify the path to this library with the -L option.
Trying some things I found online, I installed MinGW and cygwin64 and added the paths to their bin folders to my PATH variable. Before that I also installed MinGW via Matlab.
My question: How do I get it to link with gfortran?
If I search C:for libgfortran I find some files, but none of them have the file ending .lib (but e.g. .dll and .a) and if I search for gfortranI find some .exe files but again, no .lib file. If I run gfortran -dumpversion in the terminal, I get 4.9.3 back, so it is obviously there somewhere. I am obviously missing something, and this is really not my forte, to say the least.

c++ mex file in matlab

I am trying to call a c++ function from matlab using a mex file.
While compiling any example mex programs given in the <root>\extern\examples\mex folder I get the same error:
Creating library C:\USERS\SONY\APPDATA\LOCAL\TEMP\MEX_AA~1\templib.x and object C:\USERS\SONY\APPDATA\LOCAL\TEMP\MEX_AA~1\templib.exp
arrayProduct.obj : error LNK2001: unresolved external symbol _fltused
LINK : error LNK2001: unresolved external symbol _DllMainCRTStartup
arrayProduct.mexw64 : fatal error LNK1120: 2 unresolved externals
I am using matlab 7.8(2009a) and compiler microsoft visual studio express 2008.
Can someone please help me?
Thanks.

MATLAB gives error while generating MEX file from Fortran source codes

When I try to generate the MEX file from the Fortran source code (TEINITG.F), Matlab always gives errors.After downloading the trial versions of Intel Visual Fortran 11.1 Microsoft Visual C++ 2008 SP1 linker, I used mex -setup to configure the environment. Then I tried to generate mex functions from FORTRAN Source Code (TEINITG.F).
However, when I type: mex TEINITG.F
Matlab shows link errors, like:
>>mex TEINITG.F
Creating library C:\Users\xue\AppData\Local\Temp\mex_TDkmp3\templib.x and object
C:\Users\xue\AppData\Local\Temp\mex_TDkmp3\templib.exp
TEINITG.obj : error LNK2019: unresolved external symbol _TEINIT referenced in function
_MEXFUNCTION
TEINITG.mexw32 : fatal error LNK1120: 1 unresolved externals
C:\PROGRA~2\MATLAB\R2010B~1\BIN\MEX.PL: Error: Link of 'TEINITG.mexw32' failed.
I am running MATLAB R2010b-32bit on windows-64 bit. Might that be the source of problem?
I do not know how to deal with this error. Do you have any suggestions that may fix this problem?

How to build levmar using MATLAB?

I am using Windows XP and matlab version is 7.10.0.
I have the levmar(Levenberg Marquardt) package from http://www.ics.forth.gr/~lourakis/levmar/levmar-2.5.tgz
In the README file, we are told to compile in matlab using mex using the following command:
mex -DHAVE_LAPACK -I.. -O -L -L levmar.c -llevmar -lclapack -lblas -lf2c.
I downloaded lapack.lib , blas.lib and f2c.lib for windows
UPDATE:
The original error got resolved after I built a vc project file given in the package.
But now there are some error messages like :
levmar.lib(misc.obj) : error LNK2019: unresolved external symbol _dgemm_ referenced in function _dlevmar_trans_mat_mat_mult
Did you create a file with a mex-function gateway? You can't just compile a c-function for Matlab; you need to do a little bit of work to take care of the I/O between Matlab and the c-code.
If you follow the steps outlined in this document, you should do fine.
You may have a look at immoptibox, which comprises Levenberg-Marquardt algorithm as well.
I just figured it out after searching a while and noticed that the levmar package included a vc project file which i needed to build and it created a file called levmar.lib .
But now I am getting some errors which involves messages like 'unable to resolve external symbols'