How I solved Matlab/Simulink S-Function error: mexa64: GLIBCXX_3.4.xx not found
Problem
When trying to run a Simulink model that uses an S-Function compiled with mex
, I encountered the following error:
Invalid MEX-file '/home/user/mysfunction.mexa64': /opt/matlab/R2025a/bin/glnxa64/../../sys/os/glnxa64/libstdc++.so.6: version `GLIBCXX_3.4.32' not found (required by /home/user/mysfunction.mexa64)
Solution
This error occurs because the version of libstdc++.so.6
that Matlab is using (/opt/matlab/R2025a/sys/os/glnxa64/libstdc++.so.6
in this case) is older than the one required by the compiled S-Function (which is used during compilation with mex
).
In my case, Matlab comes with GLIBCXX_3.4.30
but my system libstdc++ is GLIBCXX_3.4.32
. This is a very minor mismatch, the system library is ever so slightly newer (Ubuntu 24.04 LTS, 2025-08-06).
I resolved this issue by deleting the libstdc++.so.6
file in the Matlab directory since it works just as well with the system’s libstdc++.so.6
file.
Before attempting this solution, ensure you have a backup of the original file.
rm /opt/matlab/R2025a/sys/os/glnxa64/libstdc++.so.*
After that, you need to restart Matlab and also recompile your S-Function using mex
. The error should have been resolved after that.