Configure mex in MATLAB 2018a Ubuntu 16.04 - matlab

I have upgrade to MATLAB R2018a on my machine with Ubuntu 16.04.
Before this new install I was able to compile MEX-files on MATLAB R2017a. But now I got an error:
Error using mex
/home/solrad/.matlab/R2018a/mex_C_glnxa64.xml not found; check that you are in the correct current folder, and check the
spelling of '/home/solrad/.matlab/R2018a/mex_C_glnxa64.xml'.
I have checked for the file on /home/solrad/.matlab/R2018a/mex_C_glnxa64.xml and the file is there.
How can I fix it so the mex command works again?

Related

problem using MATLAB(R2019b) controller in Webots R2020a revision 1

OS: both of Windows 10, Ubuntu (64bit)
MATLAB: R2019a, R2019b
Webots: R2020a revision 1
World file: webots/projects/languages/matlab/worlds/e-puck_matlab.wbt
Problem: Can not run MATLAB example
[matlab] Could not find file allincludes.h.
[matlab] Error in loadlibrary
[matlab] Error in launcher (line 74)
[matlab] loadlibrary( ...
Both OS show the same message "loadlibrary".
How can I fix it?
I had the same problem in Ubuntu 18.04.3. Webots 2020a-rev1 was installed with .deb file.
For me, WEBOTS_HOME = '/usr/local/webots/'
The problem is that all paths (in include files ...) are defined with matlab for webots directly in WEBOTS_HOME/lib. And in 2020a it seems that there is a new directory which is WEBOTS_HOME/lib/controller. So all paths are wrong.
The solution is this one:
cd /usr/local/webots/lib
sudo cp -r controller/matlab/ .
Hope this helps.
Goupil

How to force MATLAB 2016a to use gcc-4.7.x instead of the one I have (gcc-5.4.1)?

There are some posts about this for the older releases of MATLAB, but they don't seem to work for R2016a.
I'm trying to install MatConvNet on Ubuntu 16.04. When I run the vl_compilenn command as described here, it gives me a warning as follows:
Building with 'gcc'.
Warning: You are using gcc version '5.4.1'. The version of gcc is not supported.
The version currently supported with MEX is '4.7.x'. For a list of currently supported
compilers see: http://www.mathworks.com/support/compilers/current_release.
I have already installed gcc-4.7 and g++-4.7 using apt-get install gcc-4.7 g++-4.7. How can I force MATLAB to use these versions and not the default ones?
Few hints, not a complete tutorial how to do it.
Probably the simplest would be to edit the MATLAB's Mex XML configuration file:
mex -setup C
cc = mex.getCompilerConfigurations('C', 'Selected')
edit(cc.MexOpt)
The mex setup usually creates a copy in your home folder (~/.matlab/<version>/mex_C_glnca64.xml), so you should be able to edit it without root.
There you probably need to change the section:
<GCC>
<cmdReturns name="which gcc" />
</GCC>
which I guess searches for the location of the gcc command to your gcc version and assigns it to the $GCC variable. Plus you can change the version name in the header.
Additionally you need to do the same for the C++ language.
This works with R2016b:
Install the required GCC version with apt install (gcc-4.9 and g++-4.9 in my case).
Create a bin folder in your home, i.e. ~/bin.
Create the following links with ln:
ln -s /usr/bin/gcc-4.9 ~/bin/gcc
ln -s /usr/bin/g++-4.9 ~/bin/g++
If using CUDA, create a file called nvcc in the ~/bin folder, with the following contents (don't forget to make it executable: chmod +x ~/bin/nvcc):
Contents:
#!/bin/sh
exec /usr/lib/nvidia-cuda-toolkit/bin/nvcc -ccbin gcc-4.9 "$#"
If necessary replace /usr/lib/nvidia-cuda-toolkit/bin/nvcc with the correct location of the nvcc binary.
Open MATLAB and follow the instructions for compiling MatConvNet.

No command MCC found

I am trying to create an executable using Matlab 2013a in Ubuntu 14.04, and after some research, I understood the following command, creates the executable
mcc -mv matlabfile.m
However, when I run this command, I get following error
No command 'mcc' found, but there are 33 similar ones
mcc: command not found
Is this an error due to Matlab installation or should I include the compiler into any path variable, so that I can access it using the command mcc.? How do I solve this?
UPDATE 1
I ran the ver command in my matlab and am showing the partial output, just to prove it includes Maltab Compiler.
Image Processing Toolbox Version 8.2 (R2013a)
Instrument Control Toolbox Version 3.3 (R2013a)
MATLAB Builder JA Version 2.2.6 (R2013a)
MATLAB Coder Version 2.4 (R2013a)
MATLAB Compiler Version 4.18.1 (R2013a)
MATLAB Distributed Computing Server Version 6.2 (R2013a)
MATLAB Report Generator Version 3.14 (R2013a)
Mapping Toolbox Version 3.7 (R2013a)
Model Predictive Control Toolbo
If you have the Matlab Compiler toolbox installed, you can either run the mcc.m function through the Matlab command line:
mcc -mv matlabfile.m
Or you can run the mcc binary directly in your shell:
/path/to/matlab/bin/mcc -mv matlabfile.m
Or you can add the folder containing the mcc binary to you PATH and then run it:
PATH="$PATH:/path/to/matlab/bin/"
mcc -mv matlabfile.m

Error compiling Matlab MEX files (Piotr's Matlab Toolbox)

I am trying to install Piotr's Matlab Toolbox (http://vision.ucsd.edu/~pdollar/toolbox/doc/) but the compile script for the mex files complains:
>> toolboxCompile
Compiling.......................................
Warning: You are using gcc version "4.6.3-1ubuntu5)". The version
currently supported with MEX is "4.2.3".
For a list of currently supported compilers see:
http://www.mathworks.com/support/compilers/current_release/
/usr/bin/ld: cannot find -lstdc++
collect2: ld returned 1 exit status
mex: link of ' "/home/josh/Desktop/Project/code/toolbox/images/private/assignToBins1.mexglx"' failed.
??? Error using ==> mex at 222
Unable to complete successfully.
Error in ==> toolboxCompile at 36
for i=1:length(fs), mex([fs{i} '.c'],opts{:},[fs{i} '.' mexext]);
end
How do I go about resolving this issue?
Before you compile mexfiles in matlab you need to configure your mex compiler.
In matlab, type:
>> mex -setup
Matlab automatically detects what compilers you have installed on your machine and allows you to pick one of them.
On Linux machines you should use gcc compiler.
Another thing you must take care of is to make sure your environment variable $LD_LIBRARY_PATH points to where your machine's libraries are installed.
In matlab you may type:
>> getenv('LD_LIBRARY_PATH')
and make sure it is correct.
Try editing toolboxCompile.m and add -v to the mex compilation command to get more verbose information on the compilation.
If you are a Linux (Ubuntu but other distro should be work) user:
In order to use some system libraries instead Matlab default libraries add this environment variable to your bashrc (~/.bashrc):
LD_PRELOAD=/lib/i386-linux-gnu/libc.so.6:/usr/lib/i386-linux-gnu/libstdc++.so.6:/lib/i386-linux-gnu/libgcc_s.so.1;
Install g++-multilib:
apt-get install g++-multilib
If you are running on a 32 bit machine edit toolboxCompile.m file and replace the line of code:
"opts = {'-output'}" with
"opts = {'CXXFLAGS=-msse2 -msse' '-output'}"

Error when trying to use mexopencv in matlab

I am trying to use mexopencv on my system which has:
Ubuntu 12.04.1 LTS
opencv 2.4.2
gcc-4.4
matlab 2012
and they all are working. I also used some c++ codes to test mex and it worked fine.
I used this to install mexopencv. Also did this because of some error I got which mentioned libstdc++.so.6
Now when I try something like:
a = cv.imread('pic.jpg');
I get:
Error using cv.imread
Invalid MEX-file '/home/primepc09/mexopencv/+cv/imread.mexa64': /usr/local/lib/libopencv_highgui.so.2.4:
undefined symbol: _ZNK9QCheckBox15minimumSizeHintEv
Any idea why I get this?
This is an unresolved symbol from QT library. Make sure you have QT installed on your system:
sudo dpkg -l | grep libqt
If you don't have it, you need to install it.