MATLAB crashes when trying to generate a C++ interface

9 views (last 30 days)
Hello,
I'm trying to build a MATLAB interface to a C++ library ORNL/TASMANIAN: The Toolkit for Adaptive Stochastic Modeling and Non-Intrusive ApproximatioN (github.com). I'm using Windows and MATLAB version 2023a. First, I build the Tasmanian library with CMake and MinGW 8.1 (as listed here Compatible Windows Compilers - MATLAB & Simulink) and install it to a custom directory, which generates the header files in <install_dir>/include directory and library .dll files in <install_dir>/lib directory. I then use the dll2lib.bat script from windows - How to generate an import library (LIB-file) from a DLL? - Stack Overflow to generate the .lib files from .dll files. After that, I run the clibPublishInterfaceWorkflow function and in the Generate C++ Interface section select all the header files and .lib files. When I click on Generate definition file, it prints "MEX configured to use 'MinGW64 Compiler (C++)' for C++ language compilation.", runs for some time, but then crashes with "Acces violation" error after there is no more RAM available (it takes up around 12GB of RAM prior to crashing, as my system has 16GB). Is this process really that memory hungry, or there is maybe some internal bug or something misconfigured at my end?

Answers (1)

Hassaan
Hassaan on 11 Jan 2024
The issue you're encountering seems to be unusually severe, suggesting there might be a problem beyond just high memory usage. Here are a few considerations and steps you can take to troubleshoot and potentially resolve the issue:
  1. Check for Memory Leaks: Ensure that there are no memory leaks in the Tasmanian library itself. While this might not be directly related to your MATLAB interface issue, memory leaks in the C++ library could manifest when interfacing with MATLAB.
  2. MATLAB and Compiler Compatibility: Double-check the compatibility of MATLAB 2023a with MinGW 8.1. Although you mentioned it's listed as compatible, ensuring the specific versions match MATLAB’s requirements is crucial.
  3. Reduce Scope: Try to limit the scope of the interface generation process. If you're selecting all header and library files at once, consider breaking this down into smaller chunks. This might help you identify if a specific component is causing the issue.
  4. Update Software: Ensure that MATLAB, MinGW, and any other related software are up to date. Sometimes, bugs related to memory handling are fixed in newer versions.
  5. Use a Different Compiler: If possible, try using a different compiler. While MinGW is compatible, MATLAB often works more seamlessly with other compilers like Microsoft Visual C++.
  6. MATLAB Support and Documentation: Check MATLAB’s documentation for any known issues or special instructions regarding interface generation with large C++ libraries. Also, consider contacting MathWorks support for guidance, as they might have more insights into issues specific to MATLAB 2023a.
  7. System Resources: Monitor system resources closely. If MATLAB consistently consumes all available memory before crashing, it might indeed be a memory-related issue. Consider trying the process on a machine with more RAM if available.
  8. Debugging and Logs: Check MATLAB's crash logs for more detailed information about the crash. This could provide insights into what part of the process is failing.
  9. Incremental Approach: Build the interface incrementally, starting with a smaller set of functions and gradually adding more. This could help isolate the problem if it's related to a specific part of the library.
Remember, interfacing with large and complex libraries can sometimes expose edge cases in compilers or interfacing tools. Your approach seems fundamentally sound, but the specific issue might require a more nuanced solution.
---------------------------------------------------------------------------------------------------------------------------------------------------
If you find the solution helpful and it resolves your issue, it would be greatly appreciated if you could accept the answer. Also, leaving an upvote and a comment are also wonderful ways to provide feedback.
Professional Interests
  • Technical Services and Consulting
  • Embedded Systems | Firmware Developement | Simulations
  • Electrical and Electronics Engineering
Feel free to contact me.

Products


Release

R2023a

Community Treasure Hunt

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

Start Hunting!