How to Call "convenc" DLL Compiled with MATLAB Library Compiler in VS2019?

14 ビュー (過去 30 日間)
Alexander Mclean
Alexander Mclean 2024 年 5 月 30 日
回答済み: Hitesh 2025 年 1 月 16 日 10:49
Has anyone experienced compiling the MATLAB built-in function "convenc" into a DLL using the MATLAB Library Compiler and then calling it in VS2019 for development? If you have any related experience or steps to share, I would greatly appreciate it!

回答 (1 件)

Hitesh
Hitesh 2025 年 1 月 16 日 10:49
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)
y = convenc(x, trellis);
end
  • 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".
#include "mclmcrrt.h"
#include "myConvenc.h"
Write C++ Code to Call the DLL:
  • Initialize MATLAB Runtime
if (!mclInitializeApplication(NULL, 0)) {
std::cerr << "Could not initialize the application." << std::endl;
return -1;
}
if (!myConvencInitialize()) {
std::cerr << "Could not initialize the library." << std::endl;
return -1;
}
  • Call the MATLAB Function:
mxArray *inputArray = mxCreateDoubleMatrix(1, N, mxREAL); // Example input
double *data = mxGetPr(inputArray);
mxArray *trellis = ...;
mxArray *outputArray = nullptr;
if (!myConvenc(1, &outputArray, inputArray, trellis)) {
std::cerr << "Error calling myConvenc function." << std::endl;
}
mxDestroyArray(inputArray);
mxDestroyArray(outputArray);
  • Terminate MATLAB Runtime:
myConvencTerminate();
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,

カテゴリ

Help Center および File ExchangeMATLAB Compiler についてさらに検索

製品


リリース

R2023b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by