Why doesn't simple MEX compilation work on Linux
23 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I am using MATLAB R2023a on Arch Linux and I am trying to compile a MEX project. However, I get the error
Error using mex
'/home/xxx/yprime.mexa64' is not a MEX file. For more information, see File is not a MEX file.
I read up on MEX and found that the most recent version of gcc provided by Arch Linux is too recent (13) compared to what MATLAB supports (10). So I installed GCC version 10 from the AUR and tried compiling using mex GCC='/usr/bin/gcc-10 program.c but I still get the same error.
If I try the example codes provided by MATLAB (like yprime.c) I manage to get a working program (even with the error above), but other code I have tried simply leads to programs that yields segmentation faults that crashes MATLAB.
Using the verbose setting doesn't give me any more info on what is erroring, so I am kind of stuck. I also checked the instructions here https://wiki.archlinux.org/title/MATLAB#Install_supported_compilers to set the compiler to the old version, but from the output it seems like MATLAB is still using the system-wide installation of the compiler, so I guess that info is a bit outdated.
If anyone has any guidance on what to do next I'd love to hear some suggestions.
3 commentaires
Réponses (1)
Narvik
le 25 Oct 2023
Hi,
I understand that you are facing an issue while trying to compile a MEX project on Linux. The error “...mexa64 is not a MEX file” may be caused by a mismatch between the runtime libraries shipped for GCC with your system OS and MATLAB.
To solve this issue, you can direct MATLAB to use the operating system’s runtime libraries instead of MATLAB shipped version. This can be done by setting the `LD_PRELOAD` environment variable and restarting MATLAB.
You can run the following sample command on your terminal:
% For libstdc++ library in Ubuntu. The system libstdc++ can be force loaded with the required version.
export LD_PRELOAD=/lib/x86_64-linux-gnu/libstdc++.so.6 matlab
As an alternative, you can allow libraries from your GCC installation to be called and remove libraries from MATLAB by following the instructions in the MATLAB answer below:
Hope this helps!
2 commentaires
Manoj
le 8 Déc 2023
Hi Narvik,
Thanks for providing this answer. But I feel that almost any user who uses mex functions or mex s-functions will run into this problem. So a cleaner solution is preferable.
I have two specific concerns with your workaround,
- What if there is a bug in glibc that crashes Simulink and the fix for that is in MathWorks shipped glibc. This happened just two years back.
- How do I make sure MATLAB always start with LD_PRELOAD set as an end user?
Maybe one better workaround would be to,
- Make mex command use glibc provided by MATLAB (instead of system one). It may have to pass some flags to gcc.
Voir également
Catégories
En savoir plus sur Write C Functions Callable from MATLAB (MEX Files) dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!