MATLAB Help: "Unknown Mex argument '-o'" [duplicate] - matlab

This question already has an answer here:
mex with MATLAB2013a Unrecognized switch: -o
(1 answer)
Closed 7 years ago.
I'm trying to run the Deformable Parts Model MATLAB code provided here and I keep getting this error when running the demo.m file. The specific lines it hangs up on are:
eval([mexcmd ' gdetect/fconvsse.cc -o fconv']);
and
eval([mexcmd ' gdetect/fconv_var_dim_MT.cc -o fconv_var_dim']);
This is a pretty popular tool for detection (cited thousands of times in subsequent papers), so it's certainly not the code itself. I'm running it on MATLAB R2014a on CentOS 6.5. The documentation does say:
The software was tested on several versions of Linux and Mac OS X using MATLAB version R2011a. Earlier versions of MATLAB should also work, though there may be compatibility issues with releases prior to 2009."
Generally R2014a runs stuff from older versions though. Does anyone know what I can do to fix this? Or at least what the '-o' command even refers to? I checked the source code being compiled but couldn't find a parser or anything.

That's probably because there is no such thing as -o flag. However, there is a CAPITAL O flag, so -O. That stands for optimizing the code so that you get the best running code given what you have coded. However, this is already enabled by default, but there is an -output flag. This is probably more along the lines of what you need, judging from the way mex is getting called. -output allows you to override how the output MEX file would be named instead of assuming the name of the MEX implementation file that is being compiled.... so in your case, that would be fconvsse or fconv_var_dim_MT.
As another recommendation, I would also recommend you enable verbose mode so you can see everything that is happening under the hood while the code is being compiled. That is enabled by the -v flag.
Therefore, do this:
eval([mexcmd ' -v gdetect/fconvsse.cc -output fconv']);
and:
eval([mexcmd ' -v gdetect/fconv_var_dim_MT.cc -output fconv_var_dim']);
For more help on mex compilation flags, see the help page: http://www.mathworks.com/help/matlab/ref/mex.html

Related

Issue with using the system-command

when I use in a terminal session
curl -help
I get the help list. When I use in MATLAB
system ('curl -help')
I get the error:
System Lookup error, curl : undefined symbol:curl_url_cleanup. Linux is Fedora based Solus 4.0
In my understanding the system command should work like this. How can I get the help file?
MATLAB modifies the LD_LIBRARY_PATH environment variable, so that its own libraries can be found. However, MATLAB comes with tons of external libraries, and usually these are older versions.
So it happens at times that a command executed through system links to a version of a library that comes with MATLAB, rather than the one that comes with the OS.
The solution is to execute the command in a "clean environment", such as the one provided by env -i:
system('env -i curl -help')

Visualizing HOG features MATLAB

I was trying to use the iHOG found in this link : http://web.mit.edu/vondrick/ihog/#code to visualize my HOG features. However, I had a compilation problem when following the steps. I am using MAC Mavericks MATLAB 2014a, does anyone ever met a compilation problem when using same system or maybe knows why? This is a screenshot of the error given by MATLAB after running 'compile' as indicated by this link https://github.com/CSAILVision/ihog/blob/master/README.md#ihog-inverting-histograms-of-oriented-gradients
I tried changing the -o to -output as told bye #rayryeng. However still I have the following error occuring:
Though this is not related to HOG, take a look at this Github page regarding mexopencv by Kota Yamaguchi: https://github.com/kyamagu/mexopencv/issues/117. The error that you are encountering was experienced in compiling his MEX OpenCV wrappers.
Essentially, the mex -o option is for MATLAB versions from R2013b and below. As of R2014a, you need to use the -output flag when using mex. You are probably using a MATLAB version that is R2014a or later. Therefore, go into the compile.m file, and change all instances of the -o flag to -output.

Calling pdftops does not work in Matlab

I want to use the export_fig package for Matlab. At one point this worked, but now it's broken. The error occurs here:
>> system('pdftops -h')
dyld: Library not loaded: /opt/local/lib/libtiff.5.dylib
Referenced from: /opt/local/bin/pdftops
Reason: Incompatible library version: pdftops requires version 8.0.0 or later, but libtiff.5.dylib provides version 6.0.0
pdftops -h: Trace/breakpoint trap
But when I call pdftops from my own bash terminal everything works fine. I suppose it must be because Matlab has some bad library paths or something, but I don't know where to go from here?
Some relevant environmental vars used by matlab:
>> system('env')
SHELL=/bin/bash
OSG_LD_LIBRARY_PATH=/Applications/MATLAB_R2013b.app/sys/openscenegraph/lib/maci64
PATH=/usr/bin:/bin:/usr/sbin:/sbin:/opt/local/bin:/opt/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/opt/X11/bin:/usr/texbin
__CHECKFIX1436934=1
XFILESEARCHPATH=/Applications/MATLAB_R2013b.app/sys/java/jre/maci64/jre/lib/locale/%L/%T/%N%S:
DYLD_FRAMEWORK_PATH=/Applications/MATLAB_R2013b.app/sys/os/maci64:/Applications/MATLAB_R2013b.app/bin/maci64/../../Contents/MacOS:/Applications/MATLAB_R2013b.app/bin/maci64:/Applications/MATLAB_R2013b.app/extern/lib/maci64:/Applications/MATLAB_R2013b.app/sys/java/jre/maci64/jre/lib/./native_threads:/Applications/MATLAB_R2013b.app/sys/java/jre/maci64/jre/lib/./server:/Applications/MATLAB_R2013b.app/sys/java/jre/maci64/jre/lib/./lib/jli
SHLVL=1
__KMP_REGISTERED_LIB_33586=0x124404710-cafeb339-libiomp5.dylib
DYLD_LIBRARY_PATH=/Applications/MATLAB_R2013b.app/sys/os/maci64:/Applications/MATLAB_R2013b.app/bin/maci64/../../Contents/MacOS:/Applications/MATLAB_R2013b.app/bin/maci64:/Applications/MATLAB_R2013b.app/extern/lib/maci64:/Applications/MATLAB_R2013b.app/sys/java/jre/maci64/jre/lib/./native_threads:/Applications/MATLAB_R2013b.app/sys/java/jre/maci64/jre/lib/./server:/Applications/MATLAB_R2013b.app/sys/java/jre/maci64/jre/lib/./lib/jli
If you take a look at the error message, MATLAB uses libtiff to call pdftops, but only has version 6.0.0. It says it needs version 8.0.0 or later. There has been a case where this happened before here on StackOverflow. Someone was trying to install mexopencv and has encountered the same error that you're talking about: Compiling mexopencv in OS X 10.9 with Xcode 5 and Matlab R2013b
Though this is unrelated to what you're doing, they encountered the libtiff error that you speak of. They provide two solutions how to fix this error:
Go into MATLAB's root directory, then go bin/os directory where os is the directory of the operating system you are using (in my case, it's maci64). To get into the root directory, in the command prompt do this: cd/(matlabroot). Once you're here, locate the libtiff.5.dylib file and rename it to something like libtiff.5.dylib.bak so that the libtiff libraries that are used are the ones that are default to your system rather than what MATLAB is using internally in the program.
Force MATLAB to point to the library that is part of the system rather than using the one built into MATLAB. As such, in MATLAB's command prompt, run this command:
setenv('DYLD_INSERT_LIBRARIES','/opt/local/lib/libtiff.5.dylib');
Once you do this, you may get further errors that are similar but are with other libraries. As such, you need to keep appending these libraries in the second parameter of setenv and colon-delimiting them until you resolve the issues. You need to make sure that you're pointing to the ones on your system rather than the ones installed with MATLAB. In your case, you have to do:
setenv('DYLD_INSERT_LIBRARIES', ...
'/opt/local/lib/libtiff.5.dylib:/opt/local/lib/l‌​ibcurl.4.dylib');
Glad this helped!

Mex cannot find a file, but "which" can

I am trying to compile a C++ function (found here). I downloaded the requisite packages, installed Microsoft Windows SDK 7.1, linked it to MATLAB using mex -setup, and then unzipped the function packages into my MATLAB path.
When I run the command:
mex -output Faddeeva_w -O Faddeeva_w_mex.cc Faddeeva.cc
I get the error message:
C:\PROGRA~1\MATLAB\R2013A\BIN\MEX.PL: Error: 'Faddeeva_w_mex.cc' not found.
But if I type which Faddeeva_w_mex.cc I get:
C:\Users\craigim\Documents\Code\Matlab\Faddeeva-MATLAB\Faddeeva_w_mex.cc
So MATLAB and the which command have no problems finding the file, but mex is lost. This is my very first attempt at compiling something with mex, so I'm really not sure where to start here. Does mex have a different path variable that I have to set?
I'm using MATLAB 2013a on a Windows 7 64bit machine with the version of SDK 7.1 that was linked from the MATLAB List of supported compilers.
Either cd into the directory containing the files (assuming they both in the same place), or specify full/relative path to the C++ files when invoking mex function
Try putting addpath('C:\Users\craigim\Documents\Code\Matlab\Faddeeva-MATLAB\'); in your m-file. The path that MATLAB uses seems to be internal and independent of whatever your OS is using.
Documentation on addpath here.
And a similar discussion here.
You may also have to set your PATH environment variable to the string returned by the command fullfile(matlabroot,'bin',computer('arch')) in MATLAB. Here are some instructions on setting environment variables for Windows and Mac or Linux
There is also a pretty good overview of building mex-files here although I get the impression that the basics are not going to answer your question.

What is a command line compiler?

What is a command line compiler?
Nowadays, you tend to have environments in which you develop code. In other words, you get an IDE (integrated development environment) which is comprised of an editor, compiler, linker, debugger and many other wonderous tools (code analysis, refactoring and so forth).
You never have to type in a command at all, preferring instead a key sequence like CTRLF5 which will build your entire project for you.
Not so in earlier days. We had to memorize all sorts of arcane commands to get our source code transformed into executables. Such beautiful constructs as:
cc -I/usr/include -c -o prog.o prog.c
cc -I/usr/include -c -o obj1.o obj1.c
as -o start.o start.s
ld -o prog -L/lib:/usr/lib prog.o obj1.o start.o -lm -lnet
Simple, no?
It was actually a great leap forward when we started using makefiles since we could hide all those arcane commands in a complex file and simply execute make from the command line. It would go away and perform all those commands for us, and only on files that needed it.
Of course, there's still a need for command-line compilers in today's world. The ability to run things like Eclipse in "headless" mode (no GUI) allow you to compile all your stuff in a batch way, without having to interact with the GUI itself.
In addition, both Borland (or whatever they're calling themselves this week) and Microsoft also provide command-line compilers for no cost (Microsoft also have their Express editions for free as well).
And gcc is also a command-line compiler. It does its one job very well and leaves it up to other applications to add a front end, if people need that sort of thing.
Don't get me wrong. I think the whole IDE thing is a wonderful idea for a quick code/debug cycle but I find that, once my applications have reached a certain level of maturity, I tend to prefer them in a form where I can edit the code with vim and just run make to produce the end product.
A command-line compiler is one that you run from the command line.
You type in gcc filename.c to compile a file (or something like that). Almost all compilers have a command-line version, and many have GUIs where you never see the command line, but the command line is still there. – Bill K Oct 5 at 16:27
(Bill K provided a nice answer in the comments... copied here and lightly edited by Mark Harrison, set to community wiki so as not to get rep.)