- Install the MATLAB Coder toolbox if it is not already installed.
- Modify the C/C++ code to expose the desired functionality as a C function with C linkage.
- Compile the modified C/C++ code into a shared library or DLL using the MATLAB Coder toolbox. You will need to include the GSL library as part of the compilation process.
- In MATLAB, use the loadlibrary function to load the shared library or DLL containing the C function.
- Use the calllib function to call the C function from MATLAB, passing in any necessary arguments and retrieving any return values.
Run C/C++ code that uses makefile in MATLAB / call via matlab
13 次查看(过去 30 天)
显示 更早的评论
Hi everyone,
I am trying to intergrate the functionality of this C/C++ code: https://github.com/chraibi/EEOver into my MATLAB program. This code is initialised by running make and has dependencies on the GSL package. Does anyone know how I could call this function in MATLAB (2022b or 2023a)?
I have tried to use the coder.ceval function avialable, but I only got it working for simple cases. The requirements of make and the GSL package has made this very difficult to understand how to implement it.
I want to change how the inputs are recieved so a text file of inputs are not needed and these parameters are provided directly from my already made MATLAB program. However, there isn't much point changing the code if I can't get it to run / build in MATLAB.
Any advice on what to try next would be amazing.
Thank you in advance for any possible help,
Matt
0 个评论
回答(1 个)
Jack
2023-3-29
Integrating external C/C++ code with MATLAB can be challenging, but it is possible to call C functions from MATLAB using the MATLAB Coder toolbox. Here are some steps to try:
It sounds like you have already attempted step 4 using the coder.ceval function, which is similar to calllib but designed for use with the MATLAB Coder toolbox. However, if you are encountering issues with dependencies and linking, it may be helpful to try compiling the code into a shared library or DLL as described in step 3.
Keep in mind that modifying and compiling external code requires a solid understanding of both the original code and the MATLAB Coder toolbox. It may be helpful to consult with a MATLAB expert or reach out to the code authors for assistance.
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!