How to structure a large MATLAB Project with custom MEX Files?
Show older comments
I work on a large MATLAB Codebase and for performance reasons we had to rewrite some functions in c++, compile them into a MEX File and then run them instead of the MATLAB Functions.
Now I store the MATLAB Code, the c++ Code and the MEX Files together in the same repository. This approach works, but is cumbersome. If I change something in the c++ Code I have to compile it by hand and then copy the new MEX File into the right spot. This approach makes debugging a nightmare and is also a bad practice as you shouldn't store artifacts together with the corresponding code.
Ideally I would like to change something in the c++ code, test it without manual compiling and then commit just the changed code.
Is there a best practice for this kind of scenario? Currently I use cmake for the mex files because of dependency management. And I don't know of any just in time mechanism of compiling the MEX Files via cmake from MATLAB.
Answers (1)
Yongjian Feng
on 3 Aug 2021
0 votes
Some advices:
- Might not be a good idea to store the MEX files in the repo. Use a build machine dedicated to compile. Then your MEX files can always be regenerated when needed
- Use unittest to test your C++ code. It is just C++ code, create C++ unite tests to test them.
- Store those unit tests in your repo as well.
2 Comments
Lukas Post
on 3 Aug 2021
Yongjian Feng
on 3 Aug 2021
Put this in your build machine script. The build script shall
- Compile the C++ code and generate MEX files
- Move the MEX files to the correct locations
Categories
Find more on MATLAB Compiler 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!