Can not build a mex file in octave using mkoctfile --mex - matlab

I am trying to build a mex file in octave. The Octave instructions says that we need to use mkoctfile --mex to build one. The file I am trying to build is in the following path:
> C:\devwork\Octave\boosted\toolbox\channels\private\rgbConvert.cpp
When I write
> mkoctfile --mex rgbConvert.cpp
I get the following error:
> g++: error: rgbConvert.cpp: No such file or directory g++: fatal
> error: no input files compilation terminated.
Note: My current directory is set correct. It is at \devwork\Octave\boosted\toolbox\channels\private
Can some one explain me why am I getting this error.

The problem is resolved using: mkoctfile --mex -DMATLAB_MEX_FILE rgbConvertMex.cpp
Hence, if you want to convert any Matlab compiled .mex file to Octave executable file, do the following two steps:
Modify wrappers.hpp file by adding #include <stdlib.h>
Save the file.
Simply run: mkoctfile --mex -DMATLAB_MEX_FILE file_name
.o file will be created.
I did it using the same and it worked fine.
Eskapp was grateful enough to release the Octave compiled MEX files. You'll need to manually add the files to the main toolbox.Please find the link here:
https://github.com/Eskapp/Piotr_vision_extrafiles_Octave
Hope it helps others :)

Related

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.

Cannot compile mex file on Windows

When I attempt to compile a .mex file on Windows, I get the following error. How can I fix this?
Error using mex
MEX cannot find library 'mwblas' specified with the -l option.
MEX looks for a file with one of the names:
libmwblas.lib
mwblas.lib
Please specify the path to this library with the -L option
As the error message states, you need to specify the directory in which the .lib file is located using the -L option or specify the full path to the .lib file as an input to mex. This library is located in matlabroot/extern/lib. So you could do something like
blas = fullfile(matlabroot,'extern','lib',computer('arch'),'microsoft', 'libmwblas.lib');
mex('-largeArrayDims', 'mymexfile.cpp', blas)
Or you can specify the folder with -L
libdir = fullfile(matlabroot,'extern','lib',computer('arch'),'microsoft');
mex('-largeArrayDims', ['-L', libdir], '-lmwblas', 'mymexfile.cpp', )
More info about compiling mex files to use LAPACK and BLAS is here

Error using mex (g++ error: No such file or directory)

I'm trying to compile a library in Matlab (http://spams-devel.gforge.inria.fr/downloads.html) on Windows, using the given compile script, but am getting the following error.
Error using mex
g++: error: /c: No such file or directory
g++: error:
/FoC:\Users\Owner\AppData\Local\Temp\mex_4354548680745_632\mexArchetypalAnalysis.obj:
No such file or directory
Error in compile (line 456)
mex(args{:});
I'm stuck here. What's going wrong and how do I fix it?
I was facing the same problem in Windows.
Try changing CFLAGS to COMPFLAGS. It worked for me.
Source: https://github.com/cjlin1/libsvm/issues/55

MATLAB include error : fatal error C1083: Cannot open include file: 'cblas.h'

I am using a optimization toolbox for solving sparse estimation problems. I have downloaded the software from SPAMS homepage and would like to create a mex-file from mexLasso.m for my application.
I transfer all the error-invoking include files to MATLAB external/include folder. In MATLAB, once I type in:
>> mex mexLasso.cpp
I receive this error:
C:\Program Files\MATLAB\R2012b\extern\include\utils.h(28)
fatal error C1083: Cannot open include file: 'cblas.h'
How can I solve this problem?
Thanks
For mex-ing: Have you setup your compiler?
>> mex -setup
Choose visual studio compiler over Matlab's lcc.
Do you have a header file cblas.h? where is it located?
Use the following flags to compile
>> mex -O -largeArrayDims -v mexLasso.cpp
The -v flag should give you a verbose output - see what are the include directories the compiler search in for header file. You can add folders to the search path with the flag -I <folder name>

matlab to c++: Cannot open include file: 'mclmcrrt.h': No such file or directory

We tried to complie the m file to c++ file by matlab complier. We had the file bulit but we got the error msg as follow.
fatal error C1083: Cannot open include file: 'mclmcrrt.h': No such file or directory
Do you have any ideas about the error msg? Any suggestion will be appreciated. Thanks a lot.
Ying
This error message is caused because you need MCR dlls.
You should locate the h file in "C:\Program Files (x86)\MATLAB\MATLAB Compiler Runtime\v715\extern\include\"
and add it to your include path in C.
Check out the manual of Matlab compiler.