Generate a dll with getters and setters for inports and outports using simulink

4 views (last 30 days)
I am trying to generate a dll for a simple model with ert_shrlib.tlc
simple_model.png
interface_simulink.png
When I try to compile, the getters and setters are not found by the compiler:
C:\Users\USER\Desktop\simple_simulink\simple_ert_shrlib_rtw>call "setup_msvc.bat"
C:\Users\USER\Desktop\simple_simulink\simple_ert_shrlib_rtw>set "VSCMD_START_DIR=C:\Users\USER\Desktop\simple_simulink\simple_ert_shrlib_rtw"
C:\Users\USER\Desktop\simple_simulink\simple_ert_shrlib_rtw>"C:\LegacyApp\VisualStudio2015\VC\VCVARSALL.BAT " amd64
Microsoft (R) Program Maintenance Utility Version 14.00.24210.0
Copyright (C) Microsoft Corporation. All rights reserved.
cl -c -nologo -GS -W4 -DWIN32 -D_MT -MT -D_CRT_SECURE_NO_WARNINGS /Od /Oy- -DCLASSIC_INTERFACE=0 -DALLOCATIONFCN=0 -DTERMFCN=1 -DONESTEPFCN=1 -DMAT_FILE=0 -DMULTI_INSTANCE_CODE=0 -DINTEGER_CODE=0 -DMT=0 -DTID01EQ=0 -DMODEL=simple -DNUMST=1 -DNCSTATES=0 -DHAVESTDIO -DMODEL_HAS_DYNAMICALLY_LOADED_SFCNS=0 @simple_comp.rsp -Fo"simple.obj" "C:\Users\USER\Desktop\simple_simulink\simple_ert_shrlib_rtw\simple.c"
simple.c
C:\Users\USER\Desktop\simple_simulink\simple_ert_shrlib_rtw\simple.c(32): warning C4013: 'set_z' undefined; assuming extern returning int
C:\Users\USER\Desktop\simple_simulink\simple_ert_shrlib_rtw\simple.c(32): warning C4013: 'get_x' undefined; assuming extern returning int
C:\Users\USER\Desktop\simple_simulink\simple_ert_shrlib_rtw\simple.c(32): warning C4013: 'get_y' undefined; assuming extern returning int
cl -c -nologo -GS -W4 -DWIN32 -D_MT -MT -D_CRT_SECURE_NO_WARNINGS /Od /Oy- -DCLASSIC_INTERFACE=0 -DALLOCATIONFCN=0 -DTERMFCN=1 -DONESTEPFCN=1 -DMAT_FILE=0 -DMULTI_INSTANCE_CODE=0 -DINTEGER_CODE=0 -DMT=0 -DTID01EQ=0 -DMODEL=simple -DNUMST=1 -DNCSTATES=0 -DHAVESTDIO -DMODEL_HAS_DYNAMICALLY_LOADED_SFCNS=0 @simple_comp.rsp -Fo"simple_capi.obj" "C:\Users\USER\Desktop\simple_simulink\simple_ert_shrlib_rtw\simple_capi.c"
simple_capi.c
### Creating shared library "..\simple_win64.dll" ...
link /RELEASE /INCREMENTAL:NO /NOLOGO kernel32.lib ws2_32.lib mswsock.lib advapi32.lib -dll -def:simple.def -out:..\simple_win64.dll @simple.rsp
Creating library ..\simple_win64.lib and object ..\simple_win64.exp
simple.obj : error LNK2019: unresolved external symbol set_z referenced in function simple_step
simple.obj : error LNK2019: unresolved external symbol get_x referenced in function simple_step
simple.obj : error LNK2019: unresolved external symbol get_y referenced in function simple_step
..\simple_win64.dll : fatal error LNK1120: 3 unresolved externals
NMAKE : fatal error U1077: 'C:\LegacyApp\VisualStudio2015\VC\BIN\amd64\link.EXE' : return code '0x460'
Stop.
The make command returned an error of 2
Error(s) encountered while building "simple_win64":
So I tried to create custom code with the setters and getters and add it to simulink. This solved the compilation error and the dll is successfuly generated. However, the getters and setters are not available on the dll api.
getsets.h
#ifndef getsets_h_
#define getsets_h_
#include "rtwtypes.h"
extern real_T get_x();
extern void set_x(real_T value);
extern real_T get_y();
extern void set_y(real_T value);
extern real_T get_z();
extern void set_z(real_T value);
#endif /* getsets_h_ */
getsets.c
#include "getsets.h"
real_T get_x(){return 1;}
void set_x(real_T value){}
real_T get_y(){return 1;}
void set_y(real_T value){}
real_T get_z(){return 1;}
void set_z(real_T value){}
How can I force Simulink to export getters and setters of the inports and outports to the dll?

Answers (0)

Categories

Find more on Introduction to Installation and Licensing in Help Center and File Exchange

Products


Release

R2019b

Community Treasure Hunt

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

Start Hunting!