Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem with rtwsfcnfmi.tlc target #371

Closed
AlphaScorpii-dev opened this issue Jul 14, 2022 · 20 comments
Closed

Problem with rtwsfcnfmi.tlc target #371

AlphaScorpii-dev opened this issue Jul 14, 2022 · 20 comments
Labels
bug Something isn't working RTWSFCN This issue is related to the S-Function based FMU export

Comments

@AlphaScorpii-dev
Copy link

AlphaScorpii-dev commented Jul 14, 2022

I am having issues with the latest version of FMIKit 3.0, when trying to create a ME FMU with the rtwsfcnfmi.tlc target.
The original model, in Simulink R2022a, is just a source plugged to an output, so nothing stellar.

Diagnostic viewer === Build (Elapsed: 2 sec) === Top model targets built:
Model  Action  Rebuild Reason                                    
=================================================================
model  Failed  Code generation information file does not exist.  

0 of 1 models built (0 models already up to date)
Build duration: 0h 0m 2.047s
Error:The specified code generation target for model 'model' cannot be used with a variable-step solver.

=== Build (Elapsed: 19 sec) ===
### Generating code and artifacts to 'Model specific' folder structure
### Generating code into build folder: D:\ToBeSaved\Documents\MATLAB\model_grt_fmi_rtw
### Invoking Target Language Compiler on model.rtw
### Using System Target File: D:\FMIKit-Simulink-3.0\grtfmi\grtfmi.tlc
### Loading TLC function libraries
### Initial pass through model to cache user defined code
.
### Caching model source code
### Writing header file model_types.h
.
### Writing header file model.h
### Writing header file model_private.h
### Writing header file rtwtypes.h
### Writing header file multiword_types.h
### Writing header file rt_nonfinite.h
### Writing source file rt_nonfinite.c
.
### Writing header file rtGetInf.h
### Writing source file rtGetInf.c
### Writing header file rtGetNaN.h
### Writing source file rtGetNaN.c
### Writing source file model.c
### Writing header file rtmodel.h
.
### Writing source file model_data.c
### TLC code generation complete.
### Writing modelDescription.xml
### Saving binary information cache.
### Running CMake generator
### Generating project
-- Selecting Windows SDK version 10.0.19041.0 to target Windows 10.0.19044.
-- The C compiler identification is MSVC 19.32.31332.0
-- The CXX compiler identification is MSVC 19.32.31332.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: C:/Program Files/Microsoft Visual Studio/2022/Professional/VC/Tools/MSVC/14.32.31326/bin/Hostx64/x64/cl.exe - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/Program Files/Microsoft Visual Studio/2022/Professional/VC/Tools/MSVC/14.32.31326/bin/Hostx64/x64/cl.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
CMAKE_C_FLAGS_RELEASE /O2 /Ob2 /DNDEBUG
CMAKE_C_FLAGS_RELEASE /Od /Ob2 /DNDEBUG
-- Configuring done
-- Generating done
-- Build files have been written to: D:/ToBeSaved/Documents/MATLAB/model_grt_fmi_rtw
### Building FMU
Microsoft (R) Build Engine version 17.2.1+52cd2da31 for .NET Framework
Copyright (C) Microsoft Corporation. All rights reserved.
Checking Build System
Building Custom Rule D:/FMIKit-Simulink-3.0/grtfmi/CMakeLists.txt
rt_matrx.c
model.c
model_data.c
rtGetInf.c
rtGetNaN.c
rt_nonfinite.c
fmi2Functions.c
Generating Code...
Creating library D:/ToBeSaved/Documents/MATLAB/model_grt_fmi_rtw/Release/model.lib and object D:/ToBeSaved/Documents/MATLAB/model_grt_fmi_rtw/Release/model.exp
model.vcxproj -> D:\ToBeSaved\Documents\MATLAB\model_grt_fmi_rtw\Release\model.dll
modelDescription.xml
binaries
binaries/win64
binaries/win64/model.dll
model.png
Building Custom Rule D:/FMIKit-Simulink-3.0/grtfmi/CMakeLists.txt
### Simulink cache artifacts for 'model' were created in 'D:\ToBeSaved\Documents\MATLAB\model.slxc'.
Build process completed successfully
Top model targets built:

Model  Action                       Rebuild Reason                                    
======================================================================================
model  Code generated and compiled  Code generation information file does not exist.  

1 of 1 models built (0 models already up to date)
Build duration: 0h 0m 18.779s

=== Build (Elapsed: 17 sec) ===
### Generating code and artifacts to 'Model specific' folder structure
### Generating code into build folder: D:\ToBeSaved\Documents\MATLAB\model_sfcn_rtw_fmi
### Invoking Target Language Compiler on model.rtw
### Using System Target File: D:\FMIKit-Simulink-3.0\rtwsfcnfmi\rtwsfcnfmi.tlc
### Loading TLC function libraries
### Initial pass through model to cache user defined code
.
### Caching model source code
Warning:Simulink Coder -- In block "model/Scope", block type "Scope": Scope blocks not currently supported for S-Function code format. Block disabled.
### Writing header file model_sf_types.h
.
### Writing header file model_sf.h
### Writing source file model_sf.c
### Writing header file rtwtypes.h
### Writing header file multiword_types.h
### Writing header file rt_nonfinite.h
### Writing source file rt_nonfinite.c
.
### Writing header file rtGetInf.h
### Writing source file rtGetInf.c
### Writing header file rtGetNaN.h
### Writing source file rtGetNaN.c
### Writing header file model_sf_private.h
### Writing header file model_sid.h
.
### Writing header file model_mid.h
### Writing source file model_sf_data.c
### Writing header file rt_defines.h
### TLC code generation complete.
### Writing modelDescription.xml
.
### Saving binary information cache.
### Generating project
-- Selecting Windows SDK version 10.0.19041.0 to target Windows 10.0.19044.
-- The C compiler identification is MSVC 19.32.31332.0
-- The CXX compiler identification is MSVC 19.32.31332.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: C:/Program Files/Microsoft Visual Studio/2022/Professional/VC/Tools/MSVC/14.32.31326/bin/Hostx64/x64/cl.exe - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/Program Files/Microsoft Visual Studio/2022/Professional/VC/Tools/MSVC/14.32.31326/bin/Hostx64/x64/cl.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
FIPXT_SHARED_MODULE
-- Configuring done
-- Generating done
-- Build files have been written to: D:/ToBeSaved/Documents/MATLAB/model_sfcn_rtw_fmi
### Building FMU
Microsoft (R) Build Engine version 17.2.1+52cd2da31 for .NET Framework
Copyright (C) Microsoft Corporation. All rights reserved.
ode1.c
D:\MATLAB\R2022a\rtw\c\src\odesup.h(160,5): warning C4047: '=': 'int_T *' differs in levels of indirection from 'int' [D:\ToBeSaved\Documents\MATLAB\model_sfcn_rtw_fmi\ode1.vcxproj]
ode1.vcxproj -> D:\ToBeSaved\Documents\MATLAB\model_sfcn_rtw_fmi\Release\ode1.lib
fmi2Functions.c
D:\FMIKit-Simulink-3.0\rtwsfcnfmi\fmi2Functions.c(130,58): warning C4113: 'void (__cdecl *)(Model *,int,const char *,...)' differs in parameter lists from 'logMessageCallback' [D:\ToBeSaved\Documents\MATLAB\model_sfcn_rtw_fmi\model.vcxproj]
D:\FMIKit-Simulink-3.0\rtwsfcnfmi\fmi2Functions.c(273,69): warning C4113: 'void (__cdecl *)(Model *,int,const char *,...)' differs in parameter lists from 'logMessageCallback' [D:\ToBeSaved\Documents\MATLAB\model_sfcn_rtw_fmi\model.vcxproj]
sfunction.c
rt_matrx.c
model_interface.c
model_sf_data.c
rtGetInf.c
rtGetNaN.c
sfcn_fmi.c
Generating Code...
Creating library D:/ToBeSaved/Documents/MATLAB/model_sfcn_rtw_fmi/Release/model.lib and object D:/ToBeSaved/Documents/MATLAB/model_sfcn_rtw_fmi/Release/model.exp
ode1.lib(ode1.obj) : error LNK2019: unresolved external symbol ssGetNumContStatesPtr referenced in function rt_CreateIntegrationData [D:\ToBeSaved\Documents\MATLAB\model_sfcn_rtw_fmi\model.vcxproj]
D:\ToBeSaved\Documents\MATLAB\model_sfcn_rtw_fmi\Release\model.dll : fatal error LNK1120: 1 unresolved externals [D:\ToBeSaved\Documents\MATLAB\model_sfcn_rtw_fmi\model.vcxproj]
Top model targets built:

Model  Action  Rebuild Reason                                    
=================================================================
model  Failed  Code generation information file does not exist.  

0 of 1 models built (0 models already up to date)
Build duration: 0h 0m 17.332s
Error:The call to rtwsfcnfmi_make_rtw_hook, during the after_make hook generated the following error:
    Failed to build FMU

The build process will terminate as a result.
Caused by:
    Failed to build FMU

=== Build (Elapsed: 21 sec) ===
### Generating code and artifacts to 'Model specific' folder structure
### Generating code into build folder: D:\ToBeSaved\Documents\MATLAB\model_sfcn_rtw_fmi
### Invoking Target Language Compiler on model.rtw
### Using System Target File: D:\FMIKit-Simulink-3.0\rtwsfcnfmi\rtwsfcnfmi.tlc
### Loading TLC function libraries
### Initial pass through model to cache user defined code
.
### Caching model source code
Warning:Simulink Coder -- In block "model/Scope", block type "Scope": Scope blocks not currently supported for S-Function code format. Block disabled.
### Writing header file model_sf_types.h
.
### Writing header file model_sf.h
### Writing source file model_sf.c
### Writing header file rtwtypes.h
### Writing header file multiword_types.h
### Writing header file rt_nonfinite.h
### Writing source file rt_nonfinite.c
.
### Writing header file rtGetInf.h
### Writing source file rtGetInf.c
### Writing header file rtGetNaN.h
### Writing source file rtGetNaN.c
### Writing header file model_sf_private.h
### Writing header file model_sid.h
.
### Writing header file model_mid.h
### Writing source file model_sf_data.c
### Writing header file rt_defines.h
### TLC code generation complete.
### Writing modelDescription.xml
.
### Saving binary information cache.
### Generating project
-- Selecting Windows SDK version 10.0.19041.0 to target Windows 10.0.19044.
-- The C compiler identification is MSVC 19.32.31332.0
-- The CXX compiler identification is MSVC 19.32.31332.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: C:/Program Files/Microsoft Visual Studio/2022/Professional/VC/Tools/MSVC/14.32.31326/bin/Hostx64/x64/cl.exe - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/Program Files/Microsoft Visual Studio/2022/Professional/VC/Tools/MSVC/14.32.31326/bin/Hostx64/x64/cl.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
FIPXT_SHARED_MODULE
-- Configuring done
-- Generating done
-- Build files have been written to: D:/ToBeSaved/Documents/MATLAB/model_sfcn_rtw_fmi
### Building FMU
Microsoft (R) Build Engine version 17.2.1+52cd2da31 for .NET Framework
Copyright (C) Microsoft Corporation. All rights reserved.
ode1.c
D:\MATLAB\R2022a\rtw\c\src\odesup.h(160,5): warning C4047: '=': 'int_T *' differs in levels of indirection from 'int' [D:\ToBeSaved\Documents\MATLAB\model_sfcn_rtw_fmi\ode1.vcxproj]
ode1.vcxproj -> D:\ToBeSaved\Documents\MATLAB\model_sfcn_rtw_fmi\Release\ode1.lib
fmi2Functions.c
D:\FMIKit-Simulink-3.0\rtwsfcnfmi\fmi2Functions.c(130,58): warning C4113: 'void (__cdecl *)(Model *,int,const char *,...)' differs in parameter lists from 'logMessageCallback' [D:\ToBeSaved\Documents\MATLAB\model_sfcn_rtw_fmi\model.vcxproj]
D:\FMIKit-Simulink-3.0\rtwsfcnfmi\fmi2Functions.c(273,69): warning C4113: 'void (__cdecl *)(Model *,int,const char *,...)' differs in parameter lists from 'logMessageCallback' [D:\ToBeSaved\Documents\MATLAB\model_sfcn_rtw_fmi\model.vcxproj]
sfunction.c
rt_matrx.c
model_interface.c
model_sf_data.c
rtGetInf.c
rtGetNaN.c
sfcn_fmi.c
Generating Code...
Creating library D:/ToBeSaved/Documents/MATLAB/model_sfcn_rtw_fmi/Release/model.lib and object D:/ToBeSaved/Documents/MATLAB/model_sfcn_rtw_fmi/Release/model.exp
ode1.lib(ode1.obj) : error LNK2019: unresolved external symbol ssGetNumContStatesPtr referenced in function rt_CreateIntegrationData [D:\ToBeSaved\Documents\MATLAB\model_sfcn_rtw_fmi\model.vcxproj]
D:\ToBeSaved\Documents\MATLAB\model_sfcn_rtw_fmi\Release\model.dll : fatal error LNK1120: 1 unresolved externals [D:\ToBeSaved\Documents\MATLAB\model_sfcn_rtw_fmi\model.vcxproj]
Top model targets built:

Model  Action  Rebuild Reason                                    
=================================================================
model  Failed  Code generation information file does not exist.  

0 of 1 models built (0 models already up to date)
Build duration: 0h 0m 21.137s
Error:The call to rtwsfcnfmi_make_rtw_hook, during the after_make hook generated the following error:
    Failed to build FMU

The build process will terminate as a result.
Caused by:
    Failed to build FMU

=== Build (Elapsed: 18 sec) ===
### Generating code and artifacts to 'Model specific' folder structure
### Generating code into build folder: D:\ToBeSaved\Documents\MATLAB\model_sfcn_rtw_fmi
### Invoking Target Language Compiler on model.rtw
### Using System Target File: D:\FMIKit-Simulink-3.0\rtwsfcnfmi\rtwsfcnfmi.tlc
### Loading TLC function libraries
### Initial pass through model to cache user defined code
.
### Caching model source code
Warning:Simulink Coder -- In block "model/Scope", block type "Scope": Scope blocks not currently supported for S-Function code format. Block disabled.
### Writing header file model_sf_types.h
.
### Writing header file model_sf.h
### Writing source file model_sf.c
### Writing header file rtwtypes.h
### Writing header file multiword_types.h
### Writing header file rt_nonfinite.h
### Writing source file rt_nonfinite.c
.
### Writing header file rtGetInf.h
### Writing source file rtGetInf.c
### Writing header file rtGetNaN.h
### Writing source file rtGetNaN.c
### Writing header file model_sf_private.h
### Writing header file model_sid.h
.
### Writing header file model_mid.h
### Writing source file model_sf_data.c
### Writing header file rt_defines.h
### TLC code generation complete.
### Writing modelDescription.xml
.
### Saving binary information cache.
### Generating project
-- Selecting Windows SDK version 10.0.19041.0 to target Windows 10.0.19044.
-- The C compiler identification is MSVC 19.32.31332.0
-- The CXX compiler identification is MSVC 19.32.31332.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: C:/Program Files/Microsoft Visual Studio/2022/Professional/VC/Tools/MSVC/14.32.31326/bin/Hostx64/x64/cl.exe - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/Program Files/Microsoft Visual Studio/2022/Professional/VC/Tools/MSVC/14.32.31326/bin/Hostx64/x64/cl.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
FIPXT_SHARED_MODULE
-- Configuring done
-- Generating done
-- Build files have been written to: D:/ToBeSaved/Documents/MATLAB/model_sfcn_rtw_fmi
### Building FMU
Microsoft (R) Build Engine version 17.2.1+52cd2da31 for .NET Framework
Copyright (C) Microsoft Corporation. All rights reserved.
Checking Build System
Building Custom Rule D:/FMIKit-Simulink-3.0/rtwsfcnfmi/CMakeLists.txt
ode1.c
D:\MATLAB\R2022a\rtw\c\src\odesup.h(160,5): warning C4047: '=': 'int_T *' differs in levels of indirection from 'int' [D:\ToBeSaved\Documents\MATLAB\model_sfcn_rtw_fmi\ode1.vcxproj]
ode1.vcxproj -> D:\ToBeSaved\Documents\MATLAB\model_sfcn_rtw_fmi\Release\ode1.lib
Building Custom Rule D:/FMIKit-Simulink-3.0/rtwsfcnfmi/CMakeLists.txt
fmi2Functions.c
D:\FMIKit-Simulink-3.0\rtwsfcnfmi\fmi2Functions.c(130,58): warning C4113: 'void (__cdecl *)(Model *,int,const char *,...)' differs in parameter lists from 'logMessageCallback' [D:\ToBeSaved\Documents\MATLAB\model_sfcn_rtw_fmi\model.vcxproj]
D:\FMIKit-Simulink-3.0\rtwsfcnfmi\fmi2Functions.c(273,69): warning C4113: 'void (__cdecl *)(Model *,int,const char *,...)' differs in parameter lists from 'logMessageCallback' [D:\ToBeSaved\Documents\MATLAB\model_sfcn_rtw_fmi\model.vcxproj]
sfunction.c
rt_matrx.c
model_interface.c
model_sf_data.c
rtGetInf.c
rtGetNaN.c
sfcn_fmi.c
Generating Code...
Creating library D:/ToBeSaved/Documents/MATLAB/model_sfcn_rtw_fmi/Release/model.lib and object D:/ToBeSaved/Documents/MATLAB/model_sfcn_rtw_fmi/Release/model.exp
ode1.lib(ode1.obj) : error LNK2019: unresolved external symbol ssGetNumContStatesPtr referenced in function rt_CreateIntegrationData [D:\ToBeSaved\Documents\MATLAB\model_sfcn_rtw_fmi\model.vcxproj]
D:\ToBeSaved\Documents\MATLAB\model_sfcn_rtw_fmi\Release\model.dll : fatal error LNK1120: 1 unresolved externals [D:\ToBeSaved\Documents\MATLAB\model_sfcn_rtw_fmi\model.vcxproj]
Top model targets built:

Model  Action  Rebuild Reason                                    
=================================================================
model  Failed  Code generation information file does not exist.  

0 of 1 models built (0 models already up to date)
Build duration: 0h 0m 17.973s
Error:The call to rtwsfcnfmi_make_rtw_hook, during the after_make hook generated the following error:
    Failed to build FMU

The build process will terminate as a result.
Caused by:
    Failed to build FMU

When looking at the C code, I find a ssGetNumContStatesPtr definition in simstruc_internal.h, but conditioned by a flag

#if defined(USE_32BIT_AND_64BIT_FIELDS)
/*
 * Set/Get number of DWork elements
 */
#define ssSetNumDWork(S, num) ((_ssSetNumDWorkSLSize(S, num)) >= -1)
/* We really should combine these with the above macros
   for USE_32BIT_AND_64BIT_FIELDS */
#define _ssSetNumDWork(S, nDWork) ((S)->sizes.numDWork = (nDWork))
#define _ssSetNumDWorkSLSize(S, nDWork) \
    ((S)->blkInfo.blkInfo2->blkInfoSLSize->sizes.numDWork = (nDWork))
#define ssGetNumDWork(S) (S)->blkInfo.blkInfo2->blkInfoSLSize->sizes.numDWork

/*
 * Set/Get number continuous states
 */
#define ssGetNumContStates(S) (S)->blkInfo.blkInfo2->blkInfoSLSize->sizes.numContStates
#define ssSetNumContStates(S, nContStates) \
    ((S)->blkInfo.blkInfo2->blkInfoSLSize->sizes.numContStates = (nContStates))

/* This is needed for codegen in file odesup.h */
#define ssGetNumContStatesPtr(S) &((S)->sizes.numContStates)

This flag is itself set in another header

/*=======================================================*
 * Determine => MODE: ACCESS 32-BIT OR 64-BIT OR BOTH SIMSTRUCT FIELDS
 */
#if defined(SFCN64)
#define USE_64BIT_FIELDS
#elif (defined(SL_INTERNAL) || defined(IS_RSIM) || defined(IS_RAPID_ACCEL)) && \
    !(defined(RTW_GENERATED_S_FUNCTION) || defined(MATLAB_MEX_FILE) || defined(S_FUNCTION_NAME))
#define USE_32BIT_AND_64BIT_FIELDS
#else
#define USE_32BIT_FIELDS
#endif

Building directly from Visual Studio fails as well.
Here is the project generated : model_sfcn_rtw_fmi.zip

@psi16181918161phi
Copy link

I have the same problem, and I also tried to trace the problem in the source code.

This is my error log after trying to build with rtwsfcnfmi.tlc target:

`### Generating code and artifacts to 'Model specific' folder structure

Generating code into build folder: F:\GitHubRepos\FMI_test_3\test_circuit_FMI_sfcn_rtw_fmi

Warning: File 'codedescriptor.dmr' not found.

Invoking Target Language Compiler on test_circuit_FMI.rtw

Using System Target File: D:\Program Files\Matlab\rtw\c\FMIKit-Simulink-3.0\rtwsfcnfmi\rtwsfcnfmi.tlc

    ### Loading TLC function libraries

Initial pass through model to cache user defined code

.

Generating code for S Function : /State-Space

Caching model source code

Writing header file test_circuit_FMI_sf_types.h

Writing header file test_circuit_FMI_sf.h

.

Writing header file rtwtypes.h

Writing header file multiword_types.h

Writing source file test_circuit_FMI_sf.c

Writing header file test_circuit_FMI_sf_private.h

Writing header file test_circuit_FMI_sid.h

Writing header file test_circuit_FMI_mid.h

.

Writing source file test_circuit_FMI_sf_data.c

Writing header file rtGetNaN.h

Writing source file rtGetNaN.c

Writing header file rt_nonfinite.h

Writing source file rt_nonfinite.c

.

Writing header file rt_defines.h

Writing header file rtGetInf.h

Writing source file rtGetInf.c

TLC code generation complete.

Writing modelDescription.xml

.

Creating HTML report file index.html

Saving binary information cache.

Generating project

-- Selecting Windows SDK version 10.0.19041.0 to target Windows 10.0.18362.
-- The C compiler identification is MSVC 19.33.31629.0
-- The CXX compiler identification is MSVC 19.33.31629.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: C:/Program Files/Microsoft Visual Studio/2022/Enterprise/VC/Tools/MSVC/14.33.31629/bin/Hostx64/x64/cl.exe - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/Program Files/Microsoft Visual Studio/2022/Enterprise/VC/Tools/MSVC/14.33.31629/bin/Hostx64/x64/cl.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
MATLAB_MEX_FILE
-- Configuring done
-- Generating done
-- Build files have been written to: F:/GitHubRepos/FMI_test_3/test_circuit_FMI_sfcn_rtw_fmi

Building FMU

MSBuild version 17.3.0+f67e3d35e for .NET Framework
ode1.c
D:\Program Files\Matlab\rtw\c\src\odesup.h(160,5): warning C4047: '=': 'int_T *' differs in levels of indirection from 'int' [F:\GitHubRepos\FMI_test_3\test_circuit_FMI_sfcn_rtw_fmi\ode1.vcxproj]
ode1.vcxproj -> F:\GitHubRepos\FMI_test_3\test_circuit_FMI_sfcn_rtw_fmi\Release\ode1.lib
fmi2Functions.c
D:\Program Files\Matlab\rtw\c\FMIKit-Simulink-3.0\rtwsfcnfmi\fmi2Functions.c(130,58): warning C4113: 'void (__cdecl *)(Model *,int,const char *,...)' differs in parameter lists from 'logMessageCallback' [F:\GitHubRepos\FMI_test_3\test_circuit_FMI_sfcn_rtw_fmi\test_circuit_FMI.vcxproj]
D:\Program Files\Matlab\rtw\c\FMIKit-Simulink-3.0\rtwsfcnfmi\fmi2Functions.c(273,69): warning C4113: 'void (__cdecl *)(Model *,int,const char *,...)' differs in parameter lists from 'logMessageCallback' [F:\GitHubRepos\FMI_test_3\test_circuit_FMI_sfcn_rtw_fmi\test_circuit_FMI.vcxproj]
sfunction.c
model_interface.c
rtGetInf.c
rtGetNaN.c
sfcn_fmi.c
test_circuit_FMI_sf_data.c
Generating Code...
Creating library F:/GitHubRepos/FMI_test_3/test_circuit_FMI_sfcn_rtw_fmi/Release/test_circuit_FMI.lib and object F:/GitHubRepos/FMI_test_3/test_circuit_FMI_sfcn_rtw_fmi/Release/test_circuit_FMI.exp
LINK : warning LNK4199: /DELAYLOAD:libmat.dll ignored; no imports found from libmat.dll [F:\GitHubRepos\FMI_test_3\test_circuit_FMI_sfcn_rtw_fmi\test_circuit_FMI.vcxproj]
LINK : warning LNK4199: /DELAYLOAD:libfixedpoint.dll ignored; no imports found from libfixedpoint.dll [F:\GitHubRepos\FMI_test_3\test_circuit_FMI_sfcn_rtw_fmi\test_circuit_FMI.vcxproj]
LINK : warning LNK4199: /DELAYLOAD:libut.dll ignored; no imports found from libut.dll [F:\GitHubRepos\FMI_test_3\test_circuit_FMI_sfcn_rtw_fmi\test_circuit_FMI.vcxproj]
ode1.lib(ode1.obj) : error LNK2019: unresolved external symbol ssGetNumContStatesPtr referenced in function rt_CreateIntegrationData [F:\GitHubRepos\FMI_test_3\test_circuit_FMI_sfcn_rtw_fmi\test_circuit_FMI.vcxproj]
F:\GitHubRepos\FMI_test_3\test_circuit_FMI_sfcn_rtw_fmi\Release\test_circuit_FMI.dll : fatal error LNK1120: 1 unresolved externals [F:\GitHubRepos\FMI_test_3\test_circuit_FMI_sfcn_rtw_fmi\test_circuit_FMI.vcxproj]
Build Summary
Top model targets built:

Model Action Rebuild Reason

test_circuit_FMI Failed Code generation information file does not exist.

0 of 1 models built (0 models already up to date)
Build duration: 0h 0m 35.464s
The call to rtwsfcnfmi_make_rtw_hook, during the after_make hook generated the following error:
Failed to build FMU

The build process will terminate as a result.

Caused by:
Failed to build FMU`

I tried with Stateflow, Simulink blocks and Simulink PowerGUI elements to test out rtwsfcnfmi.tlc, and I got the same error. There is some problem with use ODE solvers, and the discrete solvers as well.

Please provide some fixes for this.

Thanks

@psi16181918161phi
Copy link

I now have the following errors when I try to use rtwsfcnfmi.tlc:

"sfunction.obj : error LNK2019: unresolved external symbol ssSetRegInputPortDimensionInfoFcn referenced in function CreateSimStructForFMI [C:\Users\lordx\Desktop\TestFMI_4\test_fmi_sfcn_rtw_fmi\test_fmi.vcxproj]
sfunction.obj : error LNK2019: unresolved external symbol ssSetRegOutputPortDimensionInfoFcn referenced in function CreateSimStructForFMI [C:\Users\lordx\Desktop\TestFMI_4\test_fmi_sfcn_rtw_fmi\test_fmi.vcxproj]"

I am using Matlab R2022b and the system is a simple subsystem with one input port and one output port.

Thanks

@t-sommer
Copy link
Contributor

Can you share the model to reproduce the problem?

@AlphaScorpii-dev
Copy link
Author

For what it’s worth, my original simulink model is in the zip file attached in the first post.

@psi16181918161phi
Copy link

For what it’s worth, my original simulink model is in the zip file attached in the first post.

@t-sommer

When I tried to test out rtwsfcnfsmi.tlc with a simple In1 and Out1 Simulink model, I keep getting errors regarding multiplication or the math settings.

I have attached all of the models in the following repo:

https://github.com/hadrianhu888/FMI_test_4

The grtfmi worked.

I think a guide of some kind to guide users on which kind of simulation should use which settings for which types of FMU generation would be helpful.

Right now, there is a lot of trial and error to get the FMU to work.

I am certain I messed up a setting somewhere, or the Simulink model itself is incorrect as noted in the error message when I ran regarding "Invalid expression. Check for missing multiplication operator, missing or unbalanced delimiters, or other syntax error. To construct matrices, use brackets instead of parentheses."

@t-sommer t-sommer added bug Something isn't working RTWSFCN This issue is related to the S-Function based FMU export labels Sep 26, 2022
t-sommer added a commit that referenced this issue Sep 27, 2022
to fix compilation on R2022a

fixes #371
@t-sommer
Copy link
Contributor

Can you give 7cf44c3 a try?

@psi16181918161phi
Copy link

psi16181918161phi commented Sep 27, 2022 via email

@AlphaScorpii-dev
Copy link
Author

AlphaScorpii-dev commented Sep 28, 2022

From what I can say, applying @t-sommer 's correction made it work for me in R2022a (just tested on a simple model, but still, that's encouraging !).
However, things break again when trying on the newer R2022b release. So @hadrianhu888 's issue seems to be support for R2022b.
On my side, here is the log I get

Build output

=== Build (Elapsed: 34 sec) ===
### Generating code and artifacts to 'Model specific' folder structure
### Generating code into build folder: D:\ToBeSaved\Documents\MATLAB\model_sfcn_rtw_fmi
### Invoking Target Language Compiler on model.rtw
### Using System Target File: D:\FMIKit-Simulink-3.0\rtwsfcnfmi\rtwsfcnfmi.tlc
### Loading TLC function libraries
### Initial pass through model to cache user defined code
### Caching model source code
Warning:Simulink Coder -- In block "model/Scope", block type "Scope": Scope blocks not currently supported for S-Function code format. Block disabled.
### Writing header file model_sf_types.h
### Writing header file model_sf.h
### Writing source file model_sf.c
### Writing header file rtwtypes.h
### Writing header file multiword_types.h
.
### Writing header file rt_nonfinite.h
### Writing source file rt_nonfinite.c
### Writing header file rtGetInf.h
### Writing source file rtGetInf.c
### Writing header file rtGetNaN.h
.
### Writing source file rtGetNaN.c
### Writing header file model_sf_private.h
### Writing header file model_sid.h
### Writing header file model_mid.h
### Writing source file model_sf_data.c
### Writing header file rt_defines.h
.
### TLC code generation complete (took 3.901s).
### Writing modelDescription.xml
.
### Saving binary information cache.
### Generating project
-- Selecting Windows SDK version 10.0.22621.0 to target Windows 10.0.19044.
-- The C compiler identification is MSVC 19.33.31630.0
-- The CXX compiler identification is MSVC 19.33.31630.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: C:/Program Files/Microsoft Visual Studio/2022/Professional/VC/Tools/MSVC/14.33.31629/bin/Hostx64/x64/cl.exe - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/Program Files/Microsoft Visual Studio/2022/Professional/VC/Tools/MSVC/14.33.31629/bin/Hostx64/x64/cl.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
FIPXT_SHARED_MODULE
-- Configuring done
-- Generating done
-- Build files have been written to: D:/ToBeSaved/Documents/MATLAB/model_sfcn_rtw_fmi
### Building FMU
MSBuild version 17.3.1+2badb37d1 for .NET Framework
ode1.c
ode1.vcxproj -> D:\ToBeSaved\Documents\MATLAB\model_sfcn_rtw_fmi\Release\ode1.lib
fmi2Functions.c
D:\FMIKit-Simulink-3.0\rtwsfcnfmi\fmi2Functions.c(130,58): warning C4113: 'void (__cdecl *)(Model *,int,const char *,...)' differs in parameter lists from 'logMessageCallback' [D:\ToBeSaved\Documents\MATLAB\model_sfcn_rtw_fmi\model.vcxproj]
D:\FMIKit-Simulink-3.0\rtwsfcnfmi\fmi2Functions.c(273,69): warning C4113: 'void (__cdecl *)(Model *,int,const char *,...)' differs in parameter lists from 'logMessageCallback' [D:\ToBeSaved\Documents\MATLAB\model_sfcn_rtw_fmi\model.vcxproj]
sfunction.c
model_interface.c
model_sf_data.c
rtGetInf.c
rtGetNaN.c
sfcn_fmi.c
Generating Code...
Creating library D:/ToBeSaved/Documents/MATLAB/model_sfcn_rtw_fmi/Release/model.lib and object D:/ToBeSaved/Documents/MATLAB/model_sfcn_rtw_fmi/Release/model.exp
sfunction.obj : error LNK2019: unresolved external symbol ssSetRegInputPortDimensionInfoFcn referenced in function CreateSimStructForFMI [D:\ToBeSaved\Documents\MATLAB\model_sfcn_rtw_fmi\model.vcxproj]
sfunction.obj : error LNK2019: unresolved external symbol ssSetRegOutputPortDimensionInfoFcn referenced in function CreateSimStructForFMI [D:\ToBeSaved\Documents\MATLAB\model_sfcn_rtw_fmi\model.vcxproj]
D:\ToBeSaved\Documents\MATLAB\model_sfcn_rtw_fmi\Release\model.dll : fatal error LNK1120: 2 unresolved externals [D:\ToBeSaved\Documents\MATLAB\model_sfcn_rtw_fmi\model.vcxproj]
Top model targets built:

Model  Action  Rebuild Reason                                    
=================================================================
model  Failed  Code generation information file does not exist.  

0 of 1 models built (0 models already up to date)
Build duration: 0h 0m 33.492s
Error:The call to rtwsfcnfmi_make_rtw_hook, during the after_make hook generated the following error:
    Failed to build FMU

The build process will terminate as a result.
Caused by:
    Failed to build FMU

@psi16181918161phi
Copy link

psi16181918161phi commented Sep 28, 2022 via email

@psi16181918161phi
Copy link

@t-sommer and @AlphaScorpii-dev

With a simple In1 and Out1 in 2022b, I get this error when using ModelExchange with rtwsfncfmi.tlc:

 Top Model Build  
### Generating code and artifacts to 'Model specific' folder structure
### Generating code into build folder: F:\GitHubRepos\FMI_test_4\test_fmi_rtwsfncfmi_mdlxchnge_sfcn_rtw_fmi
 Build Summary  
Top model targets built:

Model                          Action  Rebuild Reason                                    
=========================================================================================
test_fmi_rtwsfncfmi_mdlxchnge  Failed  Code generation information file does not exist.  

0 of 1 models built (0 models already up to date)
Build duration: 0h 0m 13.242s
Invalid expression. Check for missing multiplication operator, missing or unbalanced delimiters, or other syntax error. To construct matrices, use brackets instead of parentheses.

My settings are:
Tunable,
Create code generation report,
Enabled all comments,
Max identifier length is 31,
custom code is disabled, S-function target settings are all allowed,
FMI is 2, Model Exchange, with In and Out as Visible Parameters, and checked all settings in FMI.
I updated my CMake to 3.24.1: D:\Program Files\Matlab\rtw\c\FMIKit-Simulink-3.0\cmake-3.24.1-windows-x86_64\bin\cmake.exe

My Solver is Fixed Step with Auto Solver.

The setting to denomial number is Gradual Underflow.

I hope the input configuration settings data along with my matlab settings and output logs can help solve this weird Build issue.

Thanks

@psi16181918161phi
Copy link

psi16181918161phi commented Oct 6, 2022

@t-sommer

Note that the above reply refers to the Github repo at:

(https://github.com/hadrianhu888/FMI_test_4

Where the results are kept.

@t-sommer
Copy link
Contributor

Can you give 4f10c23 at try with R2022b?

@psi16181918161phi
Copy link

psi16181918161phi commented Oct 10, 2022 via email

@psi16181918161phi
Copy link

psi16181918161phi commented Oct 10, 2022 via email

@AlphaScorpii-dev
Copy link
Author

On my side, the FMU build goes on without mistake.
The ME FMU is imported correctly in Dymola, and generates the expected output.
On the other hand, the CS FMU generates wrong outputs (for instance, the output of my integrator is zero, no matter what).
For reference, the very same model with same settings, when built with grtfmi.tlc, returns the correct values.

@t-sommer
Copy link
Contributor

2ee227f should work for Co-Simulation now.

@psi16181918161phi
Copy link

psi16181918161phi commented Oct 11, 2022 via email

@t-sommer
Copy link
Contributor

I cannot reproduce the problem with R2022b.

t-sommer added a commit that referenced this issue Oct 12, 2022
to fix compilation on R2022a

see #371
t-sommer added a commit that referenced this issue Oct 12, 2022
and use integer MATLAB_VERSION

fixes #371
t-sommer added a commit that referenced this issue Oct 12, 2022
to fix compilation on R2022a

see #371
@t-sommer
Copy link
Contributor

If the problem persists, please open a new issue and provide steps to reproduce the problem.

@psi16181918161phi
Copy link

I tested the issue with r2022b tonight, and the build went successfully.

I also updated my Cmake to 3.25.0-rc1, and both CS and ME work.

See the repository at: https://github.com/hadrianhu888/FMI_test_4.

Is there some way to do a pull request to incorporate the changes I made on my local machine into the repo?

I would love to more directly contribute to this repo and learn what to update in the source code for rtwsfcnfmi and grtfmi as Matlab moves to matlab r2023a and matlab r2023b versions.

Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working RTWSFCN This issue is related to the S-Function based FMU export
Projects
None yet
Development

No branches or pull requests

3 participants