CATIA-Systems / FMPy

Simulate Functional Mockup Units (FMUs) in Python
Other
439 stars 118 forks source link

FMU does not compile to x86_64 MacOS with Modelica.Blocks.Tables.CombiTable1Ds #599

Closed attila-balint-kul closed 1 week ago

attila-balint-kul commented 1 year ago

I am having trouble with the compilation of any Modelica model from linux to MacOS that contains a Modelica.Blocks.Tables.CombiTable1Ds. I am running OMEdit through XQuartz using the openmodelica/openmodelica:v1.21.0-gui docker image from an Intel MacBook Pro running MacOS 13.4.1. The project runs in virtual environment using python 3.10 with FMPy-0.3.16 installed.

With C code compilation I reached the end of my knowledge and would appreciate the support.

Clang:

Apple clang version 14.0.3 (clang-1403.0.22.14.1)
Target: x86_64-apple-darwin22.5.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin

I created a simplest possible model to reproduce with 1 input, 1 output and a CombiTable.

model TableTest
  Modelica.Blocks.Tables.CombiTable1Ds table(extrapolation = Modelica.Blocks.Types.Extrapolation.HoldLastPoint,smoothness = Modelica.Blocks.Types.Smoothness.LinearSegments, table = [0, 0; 1, 10; 2, 0; 3, 10; 4, 0; 5, 10])  annotation(
    Placement(visible = true, transformation(origin = {0, 0}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
  Modelica.Blocks.Interfaces.RealInput real_setpoint annotation(
    Placement(visible = true, transformation(origin = {-120, 0}, extent = {{-20, -20}, {20, 20}}, rotation = 0), iconTransformation(origin = {-94, 6}, extent = {{-20, -20}, {20, 20}}, rotation = 0)));
  Modelica.Blocks.Interfaces.RealOutput real_output annotation(
    Placement(visible = true, transformation(origin = {110, 0}, extent = {{-10, -10}, {10, 10}}, rotation = 0), iconTransformation(origin = {64, -2}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
equation
  connect(real_setpoint, table.u) annotation(
    Line(points = {{-120, 0}, {-12, 0}}, color = {0, 0, 127}));
  connect(table.y[1], real_output) annotation(
    Line(points = {{12, 0}, {110, 0}}, color = {0, 0, 127}));
end TableTest;

Screenshot 2023-09-16 at 13 28 56

I needed to cut part of the logs, but can provide the full if needed.

Compiling platform binary...
/var/folders/4_/c4l2565153bc5hqxs6vx1pr80000gp/T/tmp1310hutu/sources
clang -c -arch x86_64 -arch arm64 -I. -I/path/to/project/venv/lib/python3.10/site-packages/fmpy/c-code  ModSim_TableTest.c ModSim_TableTest_functions.c ModSim_TableTest_records.c ModSim_TableTest_01exo.c ModSim_TableTest_02nls.c ModSim_TableTest_03lsy.c ModSim_TableTest_04set.c ModSim_TableTest_05evt.c ModSim_TableTest_06inz.c ModSim_TableTest_07dly.c ModSim_TableTest_08bnd.c ModSim_TableTest_09alg.c ModSim_TableTest_10asr.c ModSim_TableTest_11mix.c ModSim_TableTest_12jac.c ModSim_TableTest_13opt.c ModSim_TableTest_14lnz.c ModSim_TableTest_15syn.c ModSim_TableTest_16dae.c ModSim_TableTest_17inl.c ModSim_TableTest_18spd.c ModSim_TableTest_init_fmu.c ModSim_TableTest_FMU.c ./gc/memory_pool.c ./gc/omc_gc.c ./util/base_array.c ./util/boolean_array.c ./util/context.c ./util/division.c ./util/doubleEndedList.c ./util/generic_array.c ./util/index_spec.c ./util/integer_array.c ./util/list.c ./util/modelica_string_lit.c ./util/modelica_string.c ./util/ModelicaUtilities.c ./util/omc_error.c ./util/omc_file.c ./util/omc_init.c ./util/omc_mmap.c ./util/omc_msvc.c ./util/omc_numbers.c ./util/parallel_helper.c ./util/rational.c ./util/real_array.c ./util/ringbuffer.c ./util/simulation_options.c ./util/string_array.c ./util/utility.c ./util/varinfo.c ./math-support/pivot.c ./simulation/jacobian_util.c ./simulation/omc_simulation_util.c ./simulation/options.c ./simulation/simulation_info_json.c ./simulation/simulation_omc_assert.c ./simulation/solver/delay.c ./simulation/solver/fmi_events.c ./simulation/solver/model_help.c ./simulation/solver/omc_math.c ./simulation/solver/spatialDistribution.c ./simulation/solver/stateset.c ./simulation/solver/synchronous.c ./simulation/solver/initialization/initialization.c ./meta/meta_modelica_catch.c && clang -shared -arch x86_64 -arch arm64 -oModSim_TableTest.dylib *.o -lm
In file included from ModSim_TableTest.c:7:
In file included from ./ModSim_TableTest_model.h:5:
In file included from ./openmodelica.h:71:
In file included from ./openmodelica_types.h:161:
./gc/omc_gc.h:223:28: warning: expression result unused [-Wunused-value]
  GC_register_displacement(0);
                           ^
./gc/omc_gc.h:227:34: warning: expression result unused [-Wunused-value]
  GC_set_force_unmap_on_gcollect(1);
                                 ^
2 warnings generated.
In file included from ModSim_TableTest.c:7:
In file included from ./ModSim_TableTest_model.h:5:
In file included from ./openmodelica.h:71:
In file included from ./openmodelica_types.h:161:
./gc/omc_gc.h:223:28: warning: expression result unused [-Wunused-value]
  GC_register_displacement(0);
                           ^
./gc/omc_gc.h:227:34: warning: expression result unused [-Wunused-value]
  GC_set_force_unmap_on_gcollect(1);
                                 ^

...

2 warnings generated.
In file included from ./simulation/solver/initialization/initialization.c:34:
In file included from ./simulation/solver/initialization/initialization.h:37:
In file included from ./simulation/solver/initialization/../../../simulation_data.h:39:
In file included from ./openmodelica.h:71:
In file included from ./openmodelica_types.h:161:
./gc/omc_gc.h:223:28: warning: expression result unused [-Wunused-value]
  GC_register_displacement(0);
                           ^
./gc/omc_gc.h:227:34: warning: expression result unused [-Wunused-value]
  GC_set_force_unmap_on_gcollect(1);
                                 ^

2 warnings generated.
Undefined symbols for architecture x86_64:
  "_ModelicaStandardTables_CombiTable1D_close", referenced from:
      _omc_Modelica_Blocks_Types_ExternalCombiTable1D_destructor in ModSim_TableTest_functions.o
  "_ModelicaStandardTables_CombiTable1D_getValue", referenced from:
      _omc_Modelica_Blocks_Tables_Internal_getTable1DValueNoDer2 in ModSim_TableTest_functions.o
  "_ModelicaStandardTables_CombiTable1D_init2", referenced from:
      _omc_Modelica_Blocks_Types_ExternalCombiTable1D_constructor in ModSim_TableTest_functions.o
  "_ModelicaStandardTables_CombiTable1D_maximumAbscissa", referenced from:
      _omc_Modelica_Blocks_Tables_Internal_getTable1DAbscissaUmax in ModSim_TableTest_functions.o
  "_ModelicaStandardTables_CombiTable1D_minimumAbscissa", referenced from:
      _omc_Modelica_Blocks_Tables_Internal_getTable1DAbscissaUmin in ModSim_TableTest_functions.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Traceback (most recent call last):
  File "/path/to/project/simulate_fmu.py", line 81, in <module>
    main()
  File "/path/to/project/simulate_fmu.py", line 76, in main
    results = simulate(fmu_path, start_values, input)
  File "/path/to/project/simulate_fmu.py", line 12, in simulate
    fmpy.util.compile_platform_binary(fmu_path)
  File "/path/to/project/venv/lib/python3.10/site-packages/fmpy/util.py", line 920, in compile_platform_binary
    binary = compile_dll(model_description=model_description,
  File "/path/to/project/venv/lib/python3.10/site-packages/fmpy/util.py", line 894, in compile_dll
    raise Exception('Failed to compile shared library')
Exception: Failed to compile shared library

Process finished with exit code 1
t-sommer commented 1 year ago

Can you try to create a CMake project form the FMU by selecting Tools > Create CMake Project... in the FMPy GUI and build the FMU with CMake?

attila-balint-kul commented 1 year ago

Thank you for the quick reply. I have created a CMake project as you instructed using the GUI and ran the cmake . command from the terminal in the project directory (please let me know if did it incorrectly).

I got the following error messages:

❯ cmake .
-- The C compiler identification is AppleClang 14.0.3.14030022
-- The CXX compiler identification is AppleClang 14.0.3.14030022
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc - 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: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
CMake Error at CMakeLists.txt:72 (add_custom_command):
  No TARGET 'PackageName.TableTest' has been created in this directory.
t-sommer commented 1 week ago

There seems to be a problem with the OpenModelica FMU export even with the latest version (v1.24.2). I've create an issue https://github.com/OpenModelica/OpenModelica/issues/13260.