Generating a 64-bit compatible .c and .h file using newer MATLAB version
25 views (last 30 days)
Show older comments
Hi all,
I hope you are doing good.
I need help in one of the issue that I am stuck to. I am working with OPAL-RT Hypersim a real-time simulator software that allows to import simulink models. Back in 2017 my teachers at university developmed some Generator Excitor, Governor and Phasor Measurement circuit and then imported them back to Hypersim as at that time Hypersim did not had those blocks in its library. These .c and .h files were generated in MATLAB/SIMULINK 2015 version which was 32-bit. However, we recently had an upgrade of simulator and our new realtime simulator is 64 bit.
So now, as I am trying to run the model in Hypersim it gives me error of comapitibility. I am looking for a way to convert those .c and .h file using a 64-bit MATLAB (more recent version 2022/2023) version however, I am unaware how to do so.
Any help or assistance in this regard will be highly helpful to me.
Kind Regards,
Hamza
7 Comments
Oliver Jaehrig
on 9 Sep 2024
The best would be to get the m-files and Simulink models which were used to generate the code from.
If this is not possible, I believe you manually need to review the code and rewrite it.
Answers (1)
Kautuk Raj
on 11 Sep 2024
Edited: Kautuk Raj
on 11 Sep 2024
To resolve the compatibility issue between 32-bit and 64-bit generated code, you can follow the steps below to recompile your existing 32-bit .c and .h files using a 64-bit version of MATLAB. By carrying out this recompilation, the conversion between 32-bit code and 64-bit code can be carried out.
1. Set Up Your Environment:
- You already have a 64-bit version of MATLAB installed.
- Install a compatible C/C++ compiler that works with your MATLAB version. Follow this documentation page for guidance: https://www.mathworks.com/help/releases/R2022a/matlab/matlab_external/choose-c-or-c-compilers.html
2. Prepare Your Files:
- Locate the original.c and.h files generated from the 32-bit MATLAB environment.
- Ensure that any dependencies or additional files needed by these.c and .h files are available.
3. Compile the Files:
- Use the mex command (https://www.mathworks.com/help/releases/R2022a/matlab/ref/mex.html) to compile the.c files. For example: mex your_file.c
4. Check for Compatibility Issues:
- If there are any errors during compilation, they might be due to deprecated functions or compatibility issues between 32-bit and 64-bit environments. Review the error messages carefully and make necessary code adjustments.
- You may need to update certain parts of the code to comply with the 64-bit architecture, such as pointer arithmetic or data type sizes.
After successful compilation and testing, import the newly compiled files into Hypersim (the real-time simulator software being used) and verify that the model runs without compatibility errors.
By following these steps, you should be able to compile and convert your existing code to work with a 64-bit environment.
0 Comments
See Also
Categories
Find more on Simulink Coder 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!