Using libsvm on Octave (Windows) - matlab

I want to use libsvm on Octave (on a Windows platform). If I understand well from the readme file, and from a dozens of posts of the internet, I don't have to make or compile anything, only copy the mexw32 and mexw64 files to my Octave working directory. If I do this, nothing happens, the error is the same as before when I want to run my sample code:
error: `libsvmread' undefined near line 7 column 11
I've tried to run make from the Octave command prompt too, but then I got other errors:
warning: unable to find mkoctfile in expected location: `c:\Program Files (x86)\
Octave-3.6.2\bin\mkoctfile-3.6.2'
warning: mkoctfile exited with failure status
But there is a mkoctfile-3.6.2.exe at the given directory...
I have already tried to edit the octaverc file too...but it didn't help.
Any ideas how to install libsvm correctly?

According to the README file in the matlab subfolder of the LIBSVM distribution (I looked at 3.13), the included binaries are only for the 64-bit version of Matlab on Windows. These binaries definitely did not work with my version of Octave on Windows! To get LIBSVM to work with Octave, we will have to build Octave-specific .mex files and put them somewhere Octave can find them.
I put together a walkthrough of the process at http://flyingpies.wordpress.com/2012/11/20/getting-libsvm-to-work-with-octave-on-windows/. In a nutshell, the steps are:
Make sure you have the Windows version of Octave built with Visual Studio (i.e. not the cygwin or mingw one.) I'm certain comparable steps can be taken with these other versions, by I didn't try them out.
Get a copy of Visual Studio 2010 or 2012. Either worked fine for me. You just need the command line C compiler and linker out of that big package. The express version of VS is available for free from Microsoft, though I didn't try that out.
In a command prompt window, run the vcvarsall.bat batch file from the Visual C folder of Visual Studio, to prime your environment for compilation.
Add the Octave bin folder to your path (C:\Program Files (x86)\Octave-3.6.2\bin on my machine). This addresses the 'cannot find mkoctfile' problem you encountered.
Edit Octave's math.h include file to reference the correct location of Visual Studio's math.h. I had to change line 74 of c:\Program Files (x86)\Octave-3.6.2\include\math.h from c:/Program Files/Microsoft Visual Studio 10.0/VC/include/math.h to c:/Program Files (x86)/Microsoft Visual Studio 11.0/VC/include/math.h.
In the same command prompt window primed with vcvarsall and the path, start Octave, navigate to the matlab subfolder of the LIBSVM distribution, and run the make command. This executes the make.m file in that folder, which will build the .mex files.
Copy the .mex files to a folder where Octave can find them. I put them in C:\Program Files (x86)\Octave-3.6.2\lib\octave\3.6.2\site\oct\i686-pc-mingw32.
At this point, if you start Octave, LIBSVM interface commands should be available. For example, the svmtrain command should run.

Related

setting up visual studio code for c++, but unable to compile

I have installed visual studio 2019 which works fine for c++ but unable to create folders and sections to store multiple code files. So thought of switching to visual studio code and followed all tutorials available on youtube and documentation. But Visual studio IDE has got nothing showing up when Run Build task is initiated, which is expected to show the c++ extension downloaded. Mingw64 is installed and checked in the terminal too.
no output or terminal opened on Run
compiler installation checked
From the image attached regarding no output in the terminal or terminal opened, it looks like the exe is made because it says 'Build finsihed succesfully'. You'll need to run this executable from the terminal.
For this, if youre in the same directory all you have to do is type the filename. helloworld.exe in the cmd, if its powershell, then ./helloworld.exe. (Also note that for exe files you dont need to explicitly mention .exe at the end of the file name)
The powershell method should work on cmd too.
And if youre not in the same directory as the executable, you can either change directory by typing cd path/to/file and proceed as above, or run directly by typing path/to/file/helloworld.exe. where path/to/file is the directory of your helloworld.exe file

Matconvnet error cl.exe not found

I have installed MatConvNet from VLFeat and I am trying to compile it. But as I am trying to run vl_compilenn it shows the following error:
vl_compilenn
Warning: CL.EXE not found in PATH. Trying to guess out of mex setup.
> In vl_compilenn>check_clpath (line 580)
In vl_compilenn (line 413)
'cl.exe' is not recognized as an internal or external command,
operable program or batch file.
Error using vl_compilenn>check_clpath (line 591)
Unable to find cl.exe
Error in vl_compilenn (line 413)
check_clpath(); % check whether cl.exe in path
install visual studio community edition ( it's the free edition ) (minwg compiler will not work)
go to C:\Program Files (x86)\Microsoft Visual Studio
search for cl.exe
take the one appropriate for your computer architecture and copy it to the folder containing the matconvnet installation
run mex -setup c++ and set it to visual studio
and you're good to go
I have added the directory with cl.exe to my system PATH variable (you need to restart Matlab after that operation) and the compilation succeeded. The check_clpath() function was unable to find proper location of cl.exe, because it was trying to find executable in directory which does not exsist:
cl_path =
'C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\bin\amd64'
after adding the cl.exe dir to PATH variable, in my case:
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\bin\Hostx64\x64
the compilation succeeded.
Matlab accepts Professional Version of Visual Studio Compiler as I found out in one of the posts on MatLab forums.
The following is an easier solution,
addpath(fullfile('C:', 'Program Files (x86)', 'Microsoft Visual Studio', '2017', 'Professional', 'VC', 'Tools', 'MSVC', '14.16.27023', 'bin', 'Hostx64', 'x64'));
Matlab Post for reference:
https://se.mathworks.com/matlabcentral/answers/271382-mex-won-t-recognize-microsoft-visual-c-compilers
This worked for me
install community visual studio 2019 professional from
https://visualstudio.microsoft.com/es/downloads/
move to the directory where the installer placed visual studio. In my case
C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional
locate the cl.exe appropriate to your host and target architecture (there are four combinations x86/x64). In my case x64/x64 resulted in
C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.27.29110\bin\Hostx64\x64
place the path in the environmental variable in your system
within matlab, move to CF2-master\external\matconvnet\matlab and execute vl_compilenn
Unfortunately MatConvNet does not support MinGW compiler in the current version. On Windows, you need to install Microsoft Visual Studio. Nowdays you can download the community edition for free, e.g. here.
One of the reasons why MatConvNet does not support MinGW is that on windows it uses the GDI+ library to speed up reading image files. You can try to compile it using:
vl_compilenn('EnableImreadJpeg', false)
cl.exe is a C++ compiler.
This message means that the program cannot find this file on your computer (either because it is actually not there, or because you did not indicate its location.)
If you actually have a C++ compiler and work with Windows, go to the properties of your PC -> advanced settings -> Environment Variables (Sorry if the names are not accurate, my computer is in French but should be something similar...).
Here you will have a field called PATH with most probably some paths already set. Modify it by adding the path of you C++ compiler (the folder containing cl.exe) and reboot your computer (your change is not taken into account otherwise).
I do not know how to do for other OS...
Otherwise, you need to download a C++ compiler. Visual Studio is free and has one.

Debug mex code using visual studio

Hi I have written a mex file and I would like to debug it using visual studio 2010. I followed steps mentioned in Mathwork website :
http://www.mathworks.com/help/matlab/matlab_external/debugging-on-microsoft-windows-platforms.html
I have also read following posts:
how to debug MATLAB .mex32/.mex64 files with Visual Studio 2010
I should mention that I can compile mex with -g code successfully but when I insert the breakpoint it says: the breakpoint cannot be currently hit. No symbols have been loaded for this document.
Then when I run the mex code from Matlab, it does not create any break point and it does not do the debugging.
According to the following :
Fixing "The breakpoint will not currently be hit. No symbols have been loaded for this document."
When I go to debug--> windows--> module--> next to matlab says cannot find or open the PDB file. I do not understand what he means when he says
" In normal projects, the assembly and its .pdb file should always have been copied by the IDE into the same folder as your .exe. The bin\Debug folder of your project. Make sure you remove one from the GAC if you've been playing with it."
my Matlab is located in C:\Program Files\MATLAB\R2012a
and the mex and pdb file is in C:\Documents\Matlab file but I copied the pdb file (I do not know it is necessary or not) to Matlab workspace. The Matlab current folder that code is running is also C:\Documents\Matlab.
Can anyone please help me to solve this problem.
Can anyone please hel me to solve this problem?

No C compiler on matlab using mex, any simple compilers/solutions?

I've been crazy on these things all day...
I installed the Matlab2010a on remote desktop (64bits windows server 2008)
then I need to use the "mex" command to recompile the code (which is already compiled at my laptop(64-bits), but it doesn't work when I copy the .mexw64 to the remote one)
But on the remote desktop, there is no Visual Studio/VC6.0. And you know it's tooooo hard and not workable to install something like that on the remote desktop...
So, are there any other solutions for me to compile the .cpp on matlab?
Thank you so much, because I've been drived crazy...Jesus...
Try the following to see what compiler is available
mex
Select a compiler:
[1] Lcc-win32 C 2.4.1 in C:\PROGRA~1\MATLAB\R2012a\sys\lcc
[2] Microsoft Visual C++ 2010 in C:\Program Files (x86)\Microsoft Visual Studio 10.0
The output shows that my MATLAB may use one of these two compilers to create mex files.
If I want to set up my another compiler, I have to use the following command
mex -setup

Compiling MEX files in Matlab 32bit running on Windows 64bit

What is the right setup to do this?
Currently when I enter mex -setup, the compiler list is empty.
I installed Visual C++ Express 2008 and Windows SDK, but the supported compilers list is still empty.
You need to manually configure the mexopts.bat file, so that your compiler is identified by the mex command. Here there is an example mexopts.bat file: http://www.playrec.co.uk/download/mexopts.bat - be sure to edit it to fit your system settings (path etc.). Also, you should put this file in the current folder when you compile the code, otherwise Matlab will use its default file.