Why does my Engine API C application fail to build on a Linux machine with a link error "libstdc++.so.6 error: __cxa_thre​ad_atexit_​impl" error with R2026a and earlier

I'm building a standalone application that links against the MATLAB 2025b Engine API libraries using Ubuntu 22.04.5 LTS. I'm building with GCC 11.4.0 (GLIBC 2.35, GNU ld 2.38) and the following build command.
gcc test_engine.c \
-I/usr/local/MATLAB/R2025b/extern/include \
-L/usr/local/MATLAB/R2025b/bin/glnxa64 \
-leng -lmx -lmat \
-o test_engine
Why am I getting the following link error?
Error:
/usr/bin/ld: /usr/local/MATLAB/R2025b/sys/os/glnxa64/libstdc++.so.6:
__cxa_thread_atexit_impl: invalid needed version 58
/usr/bin/ld: error adding symbols: bad value
collect2: error: ld returned 1 exit status

 Accepted Answer

This issue may occur on Linux systems with releases R2026a and earlier. The external gcc link is failing because it is referencing the "sys/os/glnxa64" version of "libstdc++.so.6", which does not have the necessary glibc symbol-version requirements and triggers the "__cxa_thread_atexit_impl" version mismatch error. 
To avoid this issue, use "mex -v -client engine" to obtain the supported compiler/linker options for the Engine API on this platform. 
>> mex -v -client engine test_engine.c
If this is successful, you can either continue building in MATLAB or use the verbose output as the template for your standalone application’s link command. For example, the verbose output shows the correct library selection, including use of "matlabroot/sys/os/glnxa64/orig/libstdc++.so.6" and MATLAB glibc shim handling. 
...
Building with 'gcc'.
/usr/bin/gcc -c -DMATLAB_DEFAULT_RELEASE=R2017b -DUSE_MEX_CMD -D_GNU_SOURCE -DMATLAB_MEX_FILE -I"<matlabroot>/extern/include" -I"<matlabroot>/simulink/include" -fexceptions -fPIC -fno-omit-frame-pointer -pthread -fwrapv -O2 -DNDEBUG -fno-predictive-commoning "test_engine.c" -o /tmp/mex_35364386190880_28328/test_engine.o
/usr/bin/gcc -pthread -Wl,--no-undefined -Wl,-rpath-link,<matlabroot>/bin/glnxa64 -O /tmp/mex_35364386190880_28328/test_engine.o "<matlabroot>/sys/os/glnxa64/orig/libstdc++.so.6" $MW_GLIBC_SHIM -L"<matlabroot>/bin/glnxa64" -lmx -lmex -lmat -lm -lstdc++ -leng -z noexecstack -o test_engine
MEX completed successfully.

More Answers (0)

Categories

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!