CATIA-Systems / FMIKit-Simulink

Import and export Functional Mock-up Units with Simulink
Other
157 stars 51 forks source link

Problem with rtwsfcnfmi.tlc target #371

Closed AlphaScorpii-dev closed 1 year ago

AlphaScorpii-dev commented 2 years ago

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

hadrianhu888 commented 2 years ago

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

hadrianhu888 commented 2 years ago

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 commented 2 years ago

Can you share the model to reproduce the problem?

AlphaScorpii-dev commented 2 years ago

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

hadrianhu888 commented 2 years ago

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 commented 2 years ago

Can you give 7cf44c3cea0db0e74ad4d78db9540f089206bbc8 a try?

hadrianhu888 commented 2 years ago

Hi,

This fix did not work either

Thanks

On Tue, Sep 27, 2022 at 08:23 Torsten Sommer @.***> wrote:

Can you give 7cf44c3 https://github.com/CATIA-Systems/FMIKit-Simulink/commit/7cf44c3cea0db0e74ad4d78db9540f089206bbc8 a try?

— Reply to this email directly, view it on GitHub https://github.com/CATIA-Systems/FMIKit-Simulink/issues/371#issuecomment-1259428577, or unsubscribe https://github.com/notifications/unsubscribe-auth/AFQE42ZZ77BZSS55JUJYEWDWALRLRANCNFSM53Q6X35Q . You are receiving this because you commented.Message ID: @.***>

-- Hadrian

AlphaScorpii-dev commented 2 years ago

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 >

hadrianhu888 commented 2 years ago

I got the same error messages about input port and output port errors. I tried the fix in my work computer and I got the math error message.

I will try again later on my personal computer.

Thanks

On Tue, Sep 27, 2022 at 22:15 Guillaume VIRY @.***> wrote:

From what I can say, applying @t-sommer https://github.com/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 https://github.com/hadrianhu888 's issue seems to be support for R2022b. On my side, here is the log I get Build output


line 418): System target file 'rtwsfcnfmi.tlc' cannot be found. === Build
(Elapsed: 55 sec) === Target definition is different from that in the
model. Updating target according to the new definition. The following
parameters were updated: Type definition ### 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 4.396s). ### 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 52.682s
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

</p>
</details>

—
Reply to this email directly, view it on GitHub
<https://github.com/CATIA-Systems/FMIKit-Simulink/issues/371#issuecomment-1260300377>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AFQE423Q3NUGUOC4NAJPXZLWAOS4ZANCNFSM53Q6X35Q>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>

-- 
Hadrian
hadrianhu888 commented 2 years ago

@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

hadrianhu888 commented 2 years ago

@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 commented 1 year ago

Can you give 4f10c23c4a627dc1e50e632f561c6feb8125cd62 at try with R2022b?

hadrianhu888 commented 1 year ago

Hi,

I can try it after 12 pm today.

On Mon, Oct 10, 2022 at 09:45 Torsten Sommer @.***> wrote:

Can you give 4f10c23 https://github.com/CATIA-Systems/FMIKit-Simulink/commit/4f10c23c4a627dc1e50e632f561c6feb8125cd62 at try with R2022b?

— Reply to this email directly, view it on GitHub https://github.com/CATIA-Systems/FMIKit-Simulink/issues/371#issuecomment-1273335461, or unsubscribe https://github.com/notifications/unsubscribe-auth/AFQE426EKIWGNSP2YNH2SV3WCQMW5ANCNFSM53Q6X35Q . You are receiving this because you were mentioned.Message ID: @.***>

-- Hadrian

hadrianhu888 commented 1 year ago

Hi,

The change did not seem to work.

This is the error message:

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 3.2578s Invalid expression. Check for missing multiplication operator, missing or unbalanced delimiters, or other syntax error. To construct matrices, use brackets instead of parentheses. Component:Simulink | Category:Block diagram error See the repository at: https://github.com/hadrianhu888/FMI_test_4.

On Mon, 10 Oct 2022 at 09:46, Hadrian H @.***> wrote:

Hi,

I can try it after 12 pm today.

On Mon, Oct 10, 2022 at 09:45 Torsten Sommer @.***> wrote:

Can you give 4f10c23 https://github.com/CATIA-Systems/FMIKit-Simulink/commit/4f10c23c4a627dc1e50e632f561c6feb8125cd62 at try with R2022b?

— Reply to this email directly, view it on GitHub https://github.com/CATIA-Systems/FMIKit-Simulink/issues/371#issuecomment-1273335461, or unsubscribe https://github.com/notifications/unsubscribe-auth/AFQE426EKIWGNSP2YNH2SV3WCQMW5ANCNFSM53Q6X35Q . You are receiving this because you were mentioned.Message ID: @.***>

-- Hadrian

-- Hadrian

B. Eng.

AlphaScorpii-dev commented 1 year ago

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 commented 1 year ago

2ee227f7327657cad1826d62f5e465df1dc43a54 should work for Co-Simulation now.

hadrianhu888 commented 1 year ago

Hi,

In the same repo I shared, I tried with both CS and ME with Matlab r2022b, and the changes did not help with the FMU generation.

I got the same error as I shared yesterday night.

Thanks,

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 3.2578s Invalid expression. Check for missing multiplication operator, missing or unbalanced delimiters, or other syntax error. To construct matrices, use brackets instead of parentheses. Component:Simulink | Category:Block diagram error See the repository at: https://github.com/hadrianhu888/FMI_test_4.

I made sure to pull in the changes each time.

Thanks,

On Tue, 11 Oct 2022 at 07:51, Torsten Sommer @.***> wrote:

2ee227f https://github.com/CATIA-Systems/FMIKit-Simulink/commit/2ee227f7327657cad1826d62f5e465df1dc43a54 should work for Co-Simulation now.

— Reply to this email directly, view it on GitHub https://github.com/CATIA-Systems/FMIKit-Simulink/issues/371#issuecomment-1274560341, or unsubscribe https://github.com/notifications/unsubscribe-auth/AFQE42ZIPEYGL7V34CIOG6TWCVIE7ANCNFSM53Q6X35Q . You are receiving this because you were mentioned.Message ID: @.***>

-- Hadrian

B. Eng.

t-sommer commented 1 year ago

I cannot reproduce the problem with R2022b.

t-sommer commented 1 year ago

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

hadrianhu888 commented 1 year ago

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.