UPDATE (December 2, 2017): We have found a workaround for the issue and included it into toolbox, this error shouldn’t appear for toolbox versions starting from 4.4.5.
Lately we have been receiving increasing number of reports from users who encounter the following error when trying to use toolbox on GNU Linux version of MATLAB:
>> addpath('/home/user/Documents/AdvanpixMCT-3.9.1.10015'); >> mp.Info Invalid MEX-file '/home/user/Documents/AdvanpixMCT-3.9.1.10015/mpimpl.mexa64': dlopen: cannot load any more object with static TLS Error in mp.Info (line 196) mpimpl(4);
The error has no relation to our toolbox – it is long standing issue with MATLAB itself, known at least since R2012b release. Overview of the problem can be found on stackoverflow or in our brief explanation below[1].
Here we focus on how to fix the issue in few simple steps.
- Navigate to the first folder on the search path of MATLAB:
>> u = userpath; >> cd(u(1:end-1));
- Create
startup.m
file in the folder (by using the mouse or commandedit
). Add there following lines:% path to toolbox - edit for your version: addpath('/home/user/Documents/AdvanpixMCT-3.9.1.10015'); % run some command from toolbox so that MATLAB has to load it BEFORE any other MEX. mp('pi');
From now on, on every start, MATLAB will load toolbox before any other MEX.
- Restart MATLAB and check if toolbox is loaded and ready to work:
>> mp.Info; --------------------------------------------------------------------- Multiprecision Computing Toolbox, (c) 2008-2016 Advanpix LLC. Version : 3.9.1 Build 10015 Platform: 64-bit (GNU Linux) Release : 2016-01-30 ..... ---------------------------------------------------------------------
These instructions are not specific to toolbox and can be used to prioritize loading of any MEX.
Update (October 30, 2016).
If instructions above did not fix the issue – try doing the following.
– Find matlabrc.m
file in matlabroot/toolbox/local
directory. This is the main script which MATLAB runs on startup.
– Place contents of our startup.m
(see 2nd step above) directly into matlabrc.m
as early as possible, before the lines:
% Execute startup MATLAB script, if it exists. if (exist('startup','file') == 2) ||... (exist('startup','file') == 6) startup end
– Restart MATLAB and check if this helps.
The TLS issue
Every MEX module requires system resources when it is being loaded into memory. The most aggressive MEX is the one compiled with TLS feature (needed for safe multi-threading).
MATLAB and its toolboxes use MEX dynamic libraries a lot. For example, the R2014b installation on GNU Linux contains 1888
MEX files in total!
At some point, when more and more MEX libraries are requested by MATLAB, allowed limit is reached and system loader restricts MATLAB from loading another MEX.
The most obvious solution would be to use TLS only where needed – most of the MEX in MATLAB do not use multi-threaded computations and no TLS is required. Probably if developers at TheMathWorks would use TLS more selectively – we would not see the issue at all.
{ 6 comments… read them below or add one }
Having similar problem loading a different mex-file package. Follow similar steps as above. Can you provide code/command to run toolbox before an other MEX.
Just call some command from your MEX in startup.m
Yes! Got it working now. Besides I was using multi-thread in my case (when compiling mex-), which probably does not work. Once I disabled it for multi-thread, everything now works fine.
Thanks for the help as well.
Thanks a lot! That worked for me!
This doesn’t work for me 🙁
And, I found a simple way to use the toolbox in Ubuntu14.04 (with MATLAB 2016a).
Open the matlab in the terminal window with
matlab -nojvm
and use addpath command in the terminal window.
Then, the toolbox is usable in MATLAB, but in this case, the problem is that ‘plot’ command is not usable.
Thank you for sharing the workaround! Hopefully MATLAB developers will fix this issue in next releases.