'bad lexical cast' exception when building Rapid Accelerator target for Simulink (independent of model)

18 views (last 30 days)
Hello,
I am currently working on a project that requires me to run a large number of simulations with different input variables. The setup works, and to try to speed up the simulations I want to run them in parallel with accelerator modes. The normal "accelerator" mode works fine, but I wanted to try Rapid Accelerator as well. For this, I have installed MinGW-64 through the official support package:
but when I try to compile my model I get the following error
"STD exception 'struct mwboost::wrapexcept<class mwboost::bad_lexical_cast>': 'bad lexical cast: source type value could not be interpreted as target' was caught."
This seems to happen no matter what model I try to compile, even example ones such as
openExample('sldemo_bounce')
I have tried performing a standalone install of MinGW-64 and added the path to the MW_MINGW64_LOC environment variable but the error persists, even though running
mex -setup -v
correctly configures MEX to use MinGW64
Can anyone provide some help? I found similar issues stating that "," should be replaced with "." in XML files, but I'm not using any XML files in my project and considering that an example project yielded that error as well I assume the issue is somwhere else.
For reference, I am using R2024b

Accepted Answer

Tom
Tom on 3 Mar 2025
I seem to have fixed the issue, I uninstalled the "MATLAB Compiler", "Simulink Compiler" and "MATLAB Support for MinGW-w64 C/C++/Fortran Compiler" packages and also re-installed MinGW64 8.1. Additionally, I uninstalled Python according to @Sivsankar's suggestion.
After setting the "MW_MINGW64_LOC" environment variable to the install folder location, (for example 'C:\mingw64'), the problem seems to have stopped and I can run rapid accelerator models
However, I am still unsure what actually caused the issue, but I am pretty certain it was an error in the MinGW64 installation.

More Answers (1)

Sivsankar
Sivsankar on 3 Mar 2025
Hi @Tom,
I encountered a similar issue while using MATLAB R2024a. Fortunately, I managed to resolve it by following these steps:
  1. Uninstall and reinstall Python on your system.
  2. Set the "PYTHONHOME" environment variable as explained in the documentation: https://www.mathworks.com/help/matlab/matlab_external/install-supported-python-implementation.html
I hope you find this information helpful.
Best regards.
  1 Comment
Tom
Tom on 3 Mar 2025
Hi Sivsankar,
Thank you for your answer, I uninstalled Python after which the model compiled successfully. I however didn't set the PYTHONHOME variable, so unsure if that is necessary.

Sign in to comment.

Products


Release

R2024b

Community Treasure Hunt

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

Start Hunting!