clibgen.generateLibraryDefinition error: the global scope has no "quick_exit" on Mac M2
Show older comments
The routine clibgen.generateLibraryDefiniton generates errors when trying to process one or more header files identified in the include path.
I’m running Matlab version R2023b, Prerelease Update 3 for ARM Macs. I’m using a MacBook Pro, with an Apple M2 Max running Ventura 13.4.1.
For each header file, the processor doesn’t like two lines in the file, “cstdlib”,” which on my machine is located at:
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1
The errors are:
Errors parsing interface generation files.
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/cstdlib(135):
error: the global scope has no "at_quick_exit"
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/cstdlib(136):
error: the global scope has no "quick_exit"
The lines of code in the cstdlib that seem to be causing the problem are:
#if !defined(_LIBCPP_CXX03_LANG)
using ::at_quick_exit _LIBCPP_USING_IF_EXISTS;
using ::quick_exit _LIBCPP_USING_IF_EXISTS;
#endif
In this case I was attempting to build an interface for libraw, version 0.21, which I have build and used on my system in C++ code and in Mex files using the new API. But the same problem occurs no matter what library I try to process.
Any suggestions on what to do would be greatly appreciated.
Accepted Answer
More Answers (2)
J Pries
on 11 Apr 2024
0 votes
This is a problem with XCode not providing implementaitons of std::quick_exit and std::at_quick_exit, and then Matlab attempting to parse those definitions. Searching around, you can find others having similar issues outside of Matlab. This was the most succicnt issue I could find that points to the issue being a change in the header file in XCode 14.3: https://youtrack.jetbrains.com/issue/KT-57848
That issue also suggestion a solution: Add the compiler flags -Dat_quick_exit=atexit and -Dquick_exit=exit. https://github.com/jetbrains/kotlin/commit/d50f585911dedec5723213da8835707ac95e1c01
Alternatively, you might have success providing dummy implementations just before including <cstdlib>.
#ifdef __APPLE__
int at_quick_exit(void (*func)()) noexcept { return 0; };
[[noreturn]] void quick_exit( int exit_code ) noexcept;
#endif
#include <cstdlib>
Both of these allowed me to successfully generate a library interface with clibgen.generateLibraryDefinition on a minimum working example. Your mileage may vary on more complex projects. The compiler flag option seems like the better solution.
Adrian
on 18 Jul 2024
0 votes
It looks like this bug was fixed in R2024a Update 5. I've tested on my code and there's no longer a need for hacking things 🎉
https://uk.mathworks.com/support/bugreports/details/3181030
Categories
Find more on Build MATLAB Interface to C/C++ Library in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!