MATLAB - Error creating maxmaci64 from jpeg_write.c - matlab

I had problems making mexmaci64 files using Mex from both jpeg_read.c and jpeg_write.c from jpeg toolbox. I asked my question here and the problem for jpeg_read solved.
but I still have a different error when I compile jpeg_write.c.
everything is the same and I didn't change any path or anything.
I don't understand why Matlab console returns this error.
Is this familiar to anybody? please let me know.
>> mex -compatibleArrayDims -I/usr/local/Cellar/jpeg/9d/include jpeg_write.c -L/usr/local/Cellar/jpeg/9d/lib -ljpeg
Building with 'Xcode with Clang'.
Error using mex
/Users/folder/jpeg_toolbox/jpeg_write.c:56:10: fatal error: 'jpegint.h' file not found
#include <jpegint.h>
^~~~~~~~~~~
1 error generated.

First off:
By pointing at the /usr/local/Cellar/jpeg/<version>/include location of the jpeg or other libraries, you're dependent on the specific version that is currently installed. You probably want to use /usr/local/opt/jpeg/include/ etc instead. /usr/local/opt is where Homebrew exposes its non-versioned presentations of its installed package contents.
So:
mex -compatibleArrayDims -I/usr/local/Cellar/jpeg/9d/include ...
This is pointing at the jpeg library. Does the jpeg library supply jpegint.h?
$ ls /usr/local/Cellar/jpeg/9d/include/
jconfig.h jerror.h jmorecfg.h jpeglib.h
Nope. So that's why it's not found. So you have to figure out where you can actually get jpegint.h from. Hit Google and consult your documentation to figure out what library you're actually trying to pull jpegint.h from, and pull that in, too, with the appropriate -I, -L, and -l flags.
If you think you have it already installed, you can use find /usr/local/Cellar -name jpegint.h to look for it. I found it in the gdcm package.
[~] $ find /usr/local/Cellar -name jpegint.h
/usr/local/Cellar/gdcm/3.0.8_1/include/gdcm-3.0/gdcmjpeg/jpegint.h
So you probably want something like:
mex -compatibleArrayDims -I/usr/local/opt/jpeg/include ...
-I/usr/local/opt/gdcm/include/gdcm-3.0/gdcmjpeg ...
jpeg_write.c ...
-L/usr/local/opt/jpeg/lib -L/usr/local/opt/gdcm/lib ...
-ljpeg -lgdcmjpeg16
(I don't know if you actually want -lgdcmjpeg8, -lgdcmjpeg12, or -lgdcmjpeg16, or maybe something else. I'm just guessing here. Consult the GDCM documentation.)

Related

My OpenCV lib path does not return when I try to find it

I am using Eclipse C++ and try to using OpenCV for the first time, everything is normal until when I use the command $ pkg-config --libs opencv to locating my library path of OpenCV, it return me like this:
-lopencv_shape -lopencv_stitching -lopencv_superres -lopencv_videostab -lopencv_aruco -lopencv_bgsegm -lopencv_bioinspired -lopencv_ccalib -lopencv_datasets -lopencv_dpm -lopencv_face -lopencv_freetype -lopencv_fuzzy -lopencv_hdf -lopencv_line_descriptor -lopencv_optflow -lopencv_video -lopencv_plot -lopencv_reg -lopencv_saliency -lopencv_stereo -lopencv_structured_light -lopencv_phase_unwrapping -lopencv_rgbd -lopencv_viz -lopencv_surface_matching -lopencv_text -lopencv_ximgproc -lopencv_calib3d -lopencv_features2d -lopencv_flann -lopencv_xobjdetect -lopencv_objdetect -lopencv_ml -lopencv_xphoto -lopencv_highgui -lopencv_videoio -lopencv_imgcodecs -lopencv_photo -lopencv_imgproc -lopencv_core
And at what I have seen in the document of OpenCV or some instruction videos, its should be the the path at the head, but with mine is not. And since I don't know where is my library path is, I cannot add the path into my program properties and run my first simple program on OpenCV. If anyone can give me solution or advise, I will very be grateful.

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.

Matlab: invalid mex file library not loaded

I have created a mex function (more specifically, using CUDA)
the compilation was successful, and I got a mex file zMul.mexmaci64
but on the execution, matlab reported an error:
Invalid MEX-file '/Users/zlw/Documents/MATLAB/lowComplexity/cbased/matMulGPU/zMul.mexmaci64':
dlopen(/Users/zlw/Documents/MATLAB/lowComplexity/cbased/matMulGPU/zMul.mexmaci64, 1):
Library not loaded: #rpath/libcublas.6.0.dylib
Referenced from: /Users/zlw/Documents/MATLAB/lowComplexity/cbased/matMulGPU/zMul.mexmaci64
Reason: image not found
What should I do do solve it?
additional info
setting the environment vars (PATH,LD_LIBRARY_PATH,DYLD_LIBRARY_PATH) in Matlab and in .bash_profile doesn't work for me
I'm pretty sure that the environment vars are set correctly because when I created an alias to the dylib file, Matlab detected it, tried to load it, but failed with message:no suitable image found
Thanks!
Use otool -L in both Matlab and UNIX console.
In Matlab:
!otool -L /path/to/zMul.mexmaci64
In UNIX console:
otool -L /path/to/zMul.mexmaci64
Try to find the difference between them. If there is a difference in dependency, that is probably breaking the MEX binary. You might need to apply the same technique for the dependent dylib objects recursively. Typically, enforcing the one appearing in UNIX console using DYLD_INSERT_LIBRARIES solves the problem.
Another possibility is the C++ runtime compatibility. If you're using OS X Mavericks, you should check that your MEX command is using libc++ but not libstdc++ in mexopts.sh. Below is my configuration example in mexopts.sh:
CC='clang'
CXX='clang++'
SDKROOT='/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/'
MACOSX_DEPLOYMENT_TARGET='10.9'
CFLAGS="$CFLAGS -Dchar16_t=uint16_t"
CXXFLAGS="$CXXFLAGS -std=c++11 -stdlib=libc++ -DCHAR16_T"
CXXLIBS="$MLIBS -lc++"
This post might help: http://www.seaandsailor.com/matlab-xcode6.html
It was easier than I thought. Just replace all 10.x with your OS X version and add -Dchar16_t=UINT16_T to CLIBS in mexopts.sh file.

Issues in compiling a mex file

I am having some issues in compiling using mex this software http://www.cmap.polytechnique.fr/~aspremon/ZIP/COVSEL.zip. When I use mex and give it the files to compile it shows the following error
error: 'CblasColMajor' undeclared (first use in this function)
I am compiling the mex file from matlab and in Mac LionOS. Any suggestions
I am using the following code to compile
mex BoxQP.c BoxQP_mex.c utils.c
Make sure the MACVERSION macro is defined, or define it yourself. It looks like the CblasColMajor enum is defined in the cblas.h file which is included on line 18 of BoxQP.h. So I'm guessing that you either need to install the cblas library or it's there by default on OSX. Here's what I had to use to compile it on Win32:
mex -v -g BoxQP_mex.c BoxQP.c utils.c -LC:\MATLAB\R2009bSP1\extern\lib\win32\microsoft -lmwblas
HTH, might want to include the line you're using to compile it if you can't figure it out.
EDIT
You'll need to find the library path for the Matlab install and then under that directory you'll need to look for extern\lib\ then look for your platform and library type like, extern\lib\linux\maxos I'm not sure what it will look like, but that's a guess. also, include the Mathworks BLAS library using, -lmwblas.

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'