Hi Alexander,
Kindly follow the following steps to understand the process of calling "convenc" DLL Compiled with MATLAB Library Compiler in VS2019.
Prepare the MATLAB Function:
- Create a MATLAB function that calls "convenc".
function y = myConvenc(x, trellis)
- Navigate to the Apps tab and select Library Compiler.
- Choose C/C++ Shared Library as the target.
- Add the MATLAB function "myConvenc.m" to the project.
- Configure additional settings as needed, such as specifying output folder.
- Click Package to compile the function into a shared library (DLL).
Set Up Visual Studio 2019 Project, Configure Project Properties and Include MATLAB Headers:
- Right-click on the project in the Solution Explorer and select Properties.
- Under C/C++ > General > Additional Include Directories, add the path to the include folder of the MATLAB runtime.
- Under Linker > General > Additional Library Directories, add the path to the MATLAB runtime library folder.
- Under Linker > Input > Additional Dependencies, add the names of the MATLAB runtime libraries"mclmcrrt".
Write C++ Code to Call the DLL:
- Initialize MATLAB Runtime
if (!mclInitializeApplication(NULL, 0)) {
std::cerr << "Could not initialize the application." << std::endl;
if (!myConvencInitialize()) {
std::cerr << "Could not initialize the library." << std::endl;
- Call the MATLAB Function:
mxArray *inputArray = mxCreateDoubleMatrix(1, N, mxREAL); // Example input
double *data = mxGetPr(inputArray);
mxArray *outputArray = nullptr;
if (!myConvenc(1, &outputArray, inputArray, trellis)) {
std::cerr << "Error calling myConvenc function." << std::endl;
mxDestroyArray(inputArray);
mxDestroyArray(outputArray);
- Terminate MATLAB Runtime:
mclTerminateApplication();
Build and Run
- Build the Visual Studio project.
- Ensure that the MATLAB Runtime is installed on your system and that its paths are set correctly.
- Run your application to execute the "convenc" function through the DLL.
For more information regarding "convenc", kindly refer to the following MATLAB documentation,