For some strange reason, without changing anything I now get in my Matlab code the following error:
??? Invalid MEX-file
'/code/Matlab/MEX/build/FXP/func_fr1x32.mexa64':
/code/Matlab/MEX/build/FXP/func_fr1x32.mexa64:
undefined symbol: mexGetVariableWithObject.
The function "mexGetVariableWithObject" is however never called from any function. I could not find any references to this function and I have no idea what it is doing. Has anyone ever seen this error? What could be the cause of it?
I compile the MEX files with gcc (Debian 4.9.2-10) 4.9.2.
For the "future generations" which may observe similar error, the problem was that the MEX file was compiled on a different version of Matlab (2017a) than on which it was later used (2008b). Recompiling the MEX files on the same Matlab version solved the issue.
Related
I'm trying to invoke Parsido function in mex file using gfortran compiler on Linux system. I use following instruction to compile:
mex '-I ${EBROOTIMKL}/mkl/include'...,
'-L ${EBROOTIMKL}/mkl/lib'...,
-lmkl_rt...,
pardiso_sym_f90.f90 ero_dep_fortran.F -output ero_dep_fortran
I can successfully compile the mex file, but when I excute, Matlab crashes without any error information. I know it might be due to the use of -lmkl_rt, which might conflict with the Intel iomp5 implementation of OpenMP which MATLAB uses.
Any suggestions will be appreciated.
I'm trying to build RTEMS (www.rtems.org) for my MicroBlaze processor, but I have an error that I can't fix.
When using autoconf, the file conftest.c is generated and requires function creat() in libc. But, libc does not have the function creat(), so it fails with an error.
Does anyone knows why this function is missing, and how can I fix it ?
I have a script in matlab that calls other libraries. I use matlab version 2012a on linux . I get below error and I don't know how to fix it.
The error is :
Invalid MEX-file '/home/XXX/nearest_neighbors.mexa64':
libflann.so.1.8: cannot open shared object file: No such file or
directory
Error in flann_search (line 82)
[indices,dists] = nearest_neighbors('find_nn', data, testset, n, params);
Error in MyScript (line 73)
[nresult, ndists] = flann_search(Ntraindata', Ntraindata', resu.KNN, struct('algorithm','composite',...
That library you are referring to - https://github.com/mariusmuja/flann/ - has the nearest_neighbors function written in MEX code. MEX code is C code that is used to interface with MATLAB. People usually write heavily computationally burdening code over in MEX as it is known to handle loops and other things faster. The inputs come from MATLAB and are sent to this MEX function, and the outputs come from the MEX function and are piped back to MATLAB. It's basically a nice black box where you can use it just like any other MATLAB function. In fact, a lot of the functions that come shipped with MATLAB have MEX wrappers written to promote acceleration.
You are getting that error because you need to compile the nearest_neighbors function so that there is a MEX wrapper that can be called in MATLAB. That wrapper is missing because you haven't compiled the code.
First, you need to set up MEX. Make sure you have a compiler that is compatible with your version of MATLAB. You can do that by visiting this link:
http://www.mathworks.com/support/compilers/R20xxy/index.html
xx is the version number that belongs to your MATLAB and y is the character code that comes after it. For example, if you are using R2013a, you would visit:
http://www.mathworks.com/support/compilers/R2013a/index.html
Once you're there, go to your Operating System and ensure you have one of those supported compilers installed. Once you have that installed, go into MATLAB, and in the command prompt, type in:
mex -setup
This will allow you to set up MEX and choose the compiler you want. Given your error, you're using Linux 64-bit, so it should be very easy for you to get GCC. Just make sure that you choose a version of GCC that is compatible with your version of MATLAB. Once you choose the compiler, you can compile the code by doing this in the command prompt:
>> mex -v -O nearest_neighbors.cpp
This should generate the nearest_neighbors MEX file for you. Once that's done, you can now run the code.
For more detailed instructions, check out FLANN's user manual - http://people.cs.ubc.ca/~mariusm/uploads/FLANN/flann_manual-1.8.4.pdf - It tells you how to build and compile it for MATLAB use.
Good luck!
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.
When I try to generate the MEX file from the Fortran source code (TEINITG.F), Matlab always gives errors.After downloading the trial versions of Intel Visual Fortran 11.1 Microsoft Visual C++ 2008 SP1 linker, I used mex -setup to configure the environment. Then I tried to generate mex functions from FORTRAN Source Code (TEINITG.F).
However, when I type: mex TEINITG.F
Matlab shows link errors, like:
>>mex TEINITG.F
Creating library C:\Users\xue\AppData\Local\Temp\mex_TDkmp3\templib.x and object
C:\Users\xue\AppData\Local\Temp\mex_TDkmp3\templib.exp
TEINITG.obj : error LNK2019: unresolved external symbol _TEINIT referenced in function
_MEXFUNCTION
TEINITG.mexw32 : fatal error LNK1120: 1 unresolved externals
C:\PROGRA~2\MATLAB\R2010B~1\BIN\MEX.PL: Error: Link of 'TEINITG.mexw32' failed.
I am running MATLAB R2010b-32bit on windows-64 bit. Might that be the source of problem?
I do not know how to deal with this error. Do you have any suggestions that may fix this problem?