[英]Matlab with external C++ function: coder.ceval pass a structure to a function
我正在嘗試使用coder.ceval()和coder.cstructname()將Simulink中的Matlab函數的結構傳遞給外部C ++函數。 當我嘗試使用Simulink中的deploy to hardware工具在Arduino Due板上運行代碼時,出現錯誤:
error: invalid use of incomplete type 'struct MyStruct'
error: forward declaration of 'struct MyStruct'
我正在使用mathworks的示例代碼,但使用的是c ++函數而不是ac函數:
標頭use_struct.h:
#include <tmwtypes.h>
typedef struct MyStruct
{
double s1;
double s2;
} MyStruct;
void use_struct(struct MyStruct *my_struct);
C ++函數use_struct.cpp:
#include <stdio.h>
#include <stdlib.h>
// #include "use_struct.h" // Doesn’t work when I include it here
extern “C” void use_struct(struct MyStruct *my_struct)
{
double x = my_struct->s1;
double y = my_struct->s2;
}
Matlab功能:
structVar.s1 = 1;
structVar.s2 = 2;
if strcmp(coder.target,'rtw'),
coder.cinclude('use_struct.h');
coder.cstructname(structVar, 'MyStruct', 'extern');
coder.ceval('use_struct', coder.ref(structVar));
end
我需要它作為以后代碼的C ++函數。 但是,我也使用了不帶外部“ C”的ac函數進行了嘗試,但是無論如何它還是不起作用。 誰能幫助我解決這個問題?
我找到了解決方案。 我還必須在use_struct.cpp中包括c標頭use_struct.h,還應包括:
extern "C"
{
#include "use_struct.h"
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.