フィルターのクリア

Mex building from C++ DLL

6 ビュー (過去 30 日間)
Tamir Vizel
Tamir Vizel 2020 年 11 月 19 日
編集済み: Mukund Sankaran 2020 年 11 月 22 日
Hi,
I have a C++ DLL and its header file. I'm trying to build a MEX function for each function in the DLL, and one of the functions has the following signature:
% // This is from the C++ header file
int myFunc( const char * const Input1, SomeStructType * Output1, int & Output2);
{
...
}
When I try to build a MEX in defining the inputs in my MATLAB workspace and then I run this command:
myFuncReturnValue = coder.ceval('myFunc', coder.ref(Input1), coder.ref(Output1), ***???***)
The error i get is:
...error C2664: 'int myFunc( const char * const Input1, SomeStructType * Output1, int & Output2)': cannot convert argument 3 from 'int16_t' to 'int &'...
I couldn't find any help defining 'int &' as a MATLAB datatype so i can't pass it into the MEX builder.
Can anyone help me with this issue please?
Thanks,
Tamir

採用された回答

Mukund Sankaran
Mukund Sankaran 2020 年 11 月 19 日
編集済み: Mukund Sankaran 2020 年 11 月 22 日
Hi Tamir,
Unfortunately, calling a C++ function that has a reference parameter in its signature is not supported in MATLAB Coder as of MATLAB R2020b. We've made an internal note of your request so we can look at lifting that limitation in the future. Meanwhile, as a workaround, the best you can do is to create a wrapper C++ function that takes a pointer, which in turn calls the function that takes the reference, as I've shown in the following simple example:
myFunc.hpp
int myFunc(int& out);
myFunc.cpp
#include "myFunc.hpp"
int myFunc(int& out)
{
out = 2;
return 5;
}
myFuncWrapper.hpp
#include "myFunc.hpp"
inline int myFuncWrapper(int* out) {
return myFunc(*out);
};
callMyFuncWrapper.m
function y = callMyFuncWrapper %#codegen
y = int32(0);
if coder.target('MATLAB')
% Executing in MATLAB, call MATLAB equivalent of
% C function myFuncWrapper
y = int32(5 + 2);
else
% Executing in generated code, call C function myFuncWrapper
coder.updateBuildInfo('addSourceFiles','myFunc.cpp');
coder.cinclude('myFuncWrapper.hpp');
in = int32(0);
y = coder.ceval('myFuncWrapper', coder.ref(in));
y = y + in;
end
end
Call codegen
>> codegen callMyFuncWrapper -report -lang:c++
Hope this helps!
  1 件のコメント
Tamir Vizel
Tamir Vizel 2020 年 11 月 22 日
I'll try it soon, Thank you :)

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGenerating Code についてさらに検索

製品


リリース

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by