Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/cuixing158/mex-file
MATLAB MEX file For C/C++ code generation
https://github.com/cuixing158/mex-file
c code-generation compile cpp matlab matlab-coder mex opencv
Last synced: about 1 month ago
JSON representation
MATLAB MEX file For C/C++ code generation
- Host: GitHub
- URL: https://github.com/cuixing158/mex-file
- Owner: cuixing158
- Created: 2023-08-12T03:55:04.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-04-08T03:42:51.000Z (11 months ago)
- Last Synced: 2024-11-12T14:13:46.169Z (3 months ago)
- Topics: c, code-generation, compile, cpp, matlab, matlab-coder, mex, opencv
- Language: MATLAB
- Homepage:
- Size: 96.7 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# MATLAB MEX file For C/C++ code generation
[](https://ww2.mathworks.cn/matlabcentral/fileexchange/133742-mex-file-code-generation)
[](https://matlab.mathworks.com/open/github/v1?repo=cuixing158/mex-file&file=OpenCV_API.m)

## OverView
In order to call external C/C++ library functions, it is generally recommended to use the [mex](https://ww2.mathworks.cn/help/matlab/ref/mex.html) built-in function to compile the source code into a mex executable file, but the disadvantage is that it is not easy to generate C/C++ code in turn if there are other matlab code mixed in. This example is just to show how to use [codegen](https://ww2.mathworks.cn/help/coder/ref/codegen.html) two-way through this process, not limited to the example itself, is a general method, another advantage is not limited to the code generation of various restrictions, fully integrated with C/C++ programming.
## Requirements
- MATLAB®
- Matlab Coder toolbox™
- [Supported and Compatible Compilers](https://ww2.mathworks.cn/en/support/requirements/supported-compilers.html)
- Your External C/C++ Library(This example uses OpenCV as an example)## How to setup
### 1.Configuring the compiler
In the command window,configure your complier.
```matlab
mex -setup C++
```### 2.Source Code Preparation
Prepare your C/C++ code and MATLAB entry-point function.Prepare the implementation of the `updateBuildInfo(buildInfo, buildContext)` member function, rewritten according to the path of the external library. (header files and library files).
### 3.Generate or Compile
Generate or compile the files you want with the `codegen` command.
For example:```matlab
imagePath = "./test_480x640x3.jpg";
input1 = coder.typeof(imagePath);
input1.StringLength=inf;
codegen -config:mex imread_opencv -args {input1} -lang:c++ -report
```