Archived OpenModelica forums. Posting is disabled.

Alternative forums include GitHub discussions or StackOverflow (make sure to read the Stack Overflow rules; you need to have well-formed questions)


Forgot password? | Forgot username? | Register

undefined reference to fmi2 functions

undefined reference to fmi2 functions

Hallo everyone,

I'm trying to implement a FMU Model exported from OMEdit for a real-time testing using dSpace's ConfigurationDesk to buid the executable for RT-Machine and i ran into some problems.

At first i got an error saying

modelname.h:5:26: fatal error: openmodelica.h: No such file or directory

and

modelname_FMU.c:16:34: fatal error: fmu2_model_interface.h: No such file or directory

both could be solve by including the paths

...\modelname\sources\include

and

...\modelname\sources\include\fmi2

respectively to successfully buld the modelname.a library

after that i gor error that said

Creating application image file ...
dsfmu_mdlfunctions.o86: In function `HiL_TechDay_Beispiel_DSFMUInitMdl':
dsfmu_mdlfunctions.cpp:(.text+0x3e): undefined reference to `HiL_TechDay_Beispiel_fmi2Instantiate'
dsfmu_mdlfunctions.o86: In function `HiL_TechDay_Beispiel_DSFMUStartMdl':
dsfmu_mdlfunctions.cpp:(.text+0xdf): undefined reference to `HiL_TechDay_Beispiel_fmi2SetupExperiment'
dsfmu_mdlfunctions.cpp:(.text+0xfd): undefined reference to `HiL_TechDay_Beispiel_fmi2EnterInitializationMode'
dsfmu_mdlfunctions.cpp:(.text+0x117): undefined reference to `HiL_TechDay_Beispiel_fmi2ExitInitializationMode'
dsfmu_mdlfunctions.cpp:(.text+0x1ca): undefined reference to `HiL_TechDay_Beispiel_fmi2Reset'
dsfmu_mdlfunctions.o86: In function `HiL_TechDay_Beispiel_DSFMUStep':
dsfmu_mdlfunctions.cpp:(.text+0x230): undefined reference to `HiL_TechDay_Beispiel_fmi2SetReal'
dsfmu_mdlfunctions.cpp:(.text+0x26a): undefined reference to `HiL_TechDay_Beispiel_fmi2DoStep'
dsfmu_mdlfunctions.cpp:(.text+0x291): undefined reference to `HiL_TechDay_Beispiel_fmi2GetReal'
dsfmu_mdlfunctions.o86: In function `HiL_TechDay_Beispiel_DSFMUProvideInputs':
dsfmu_mdlfunctions.cpp:(.text+0x4b6): undefined reference to `HiL_TechDay_Beispiel_fmi2SetReal'
dsfmu_mdlfunctions.o86: In function `HiL_TechDay_Beispiel_DSFMUGetOutputs':
dsfmu_mdlfunctions.cpp:(.text+0x576): undefined reference to `HiL_TechDay_Beispiel_fmi2GetReal'
dsfmu_mdlfunctions.o86: In function `HiL_TechDay_Beispiel_DSFMUStopMdl':
dsfmu_mdlfunctions.cpp:(.text+0x71a): undefined reference to `HiL_TechDay_Beispiel_fmi2Terminate'
collect2.exe: error: ld returned 1 exit status
OPUS MAKE: Shell line exit status 1. Stop.
Make failed

my knowlage in c/cpp flags and compiling or in general is very limited to understand what happend with that error.  current/big_smile

I know its not directly OpenModelica realted topic but maybe someone had an experience with working on ConfigurationDesk or more understaing about the error and could point out to me what/where shoud I start to read to understand the problem.

Thank you in advance

Best regards

Re: undefined reference to fmi2 functions

Hi Aronimo23,
I jump here from the other post... I'm not used to RT.machines, but can you share your makefile/command line?
I think that something big is missing.

Re: undefined reference to fmi2 functions

Hi DarioMangoni,

thanks for the reply and help.  it is the generated makefile from OMEdit so i think its pretty much a standard template. I dont know if i had much option to make this works. because the software that the fmu imported to doesn't give so moch ouption on how to compile the build for the RT-machine. That or my knowledge is not sufficient enough.

once again thank you for your help.

Cheers
Arinomo23

Code:

# Makefile generated by OpenModelica

CC=gcc
AR=@AR@
CFLAGS=-Os -falign-functions -fno-ipa-pure-const -mstackrealign -msse2 -mfpmath=sse
LD=$(CC) -shared
LDFLAGS=-L"C:/OpenModelica1.13.264bit//lib//omc" -Wl,-rpath,"C:/OpenModelica1.13.264bit//lib//omc" -fopenmp -Wl,-Bstatic -lregex -ltre -lintl -liconv -lexpat -lomcgc -lpthread -loleaut32 -limagehlp -lhdf5 -lz -lszip -Wl,-Bdynamic  -lSimulationRuntimeFMI  -Wl,-Bstatic -lregex -ltre -lintl -liconv -static-libgcc -lpthread -lm -lgfortranbegin -lgfortran -lquadmath -lmingw32 -lgcc_eh -lmoldname -lmingwex -lmsvcrt -luser32 -lkernel32 -ladvapi32 -lshell32 -limagehlp -lopenblas -lhdf5 -lz -lszip -Wl,-Bdynamic
DLLEXT=.dll
NEED_RUNTIME=
NEED_DGESV=
FMIPLATFORM=win64
# Note: Simulation of the fmu with dymola does not work with -finline-small-functions (enabled by most optimization levels)
CPPFLAGS=-DOMC_MINIMAL_RUNTIME=1 -DCMINPACK_NO_DLL=1 -Wl,--output-def=HiL_TechDay.def
OMC_NUM_LINEAR_SYSTEMS=0
OMC_NUM_NONLINEAR_SYSTEMS=0
OMC_NUM_MIXED_SYSTEMS=0
OMC_NDELAY_EXPRESSIONS=0
OMC_NVAR_STRING=0

override CPPFLAGS += -Iinclude/ -Iinclude/fmi2 -I.    -DOMC_MODEL_PREFIX=HiL_TechDay_Beispiel -DOMC_NUM_MIXED_SYSTEMS=0 -DOMC_NUM_LINEAR_SYSTEMS=0 -DOMC_NUM_NONLINEAR_SYSTEMS=0 -DOMC_NDELAY_EXPRESSIONS=0 -DOMC_NVAR_STRING=0

MAINFILE=HiL_TechDay_Beispiel_FMU.c
MAINOBJ=HiL_TechDay_Beispiel_FMU.o
CFILES=HiL_TechDay_Beispiel.c HiL_TechDay_Beispiel_functions.c HiL_TechDay_Beispiel_records.c \
HiL_TechDay_Beispiel_01exo.c HiL_TechDay_Beispiel_02nls.c HiL_TechDay_Beispiel_03lsy.c HiL_TechDay_Beispiel_04set.c HiL_TechDay_Beispiel_05evt.c HiL_TechDay_Beispiel_06inz.c HiL_TechDay_Beispiel_07dly.c \
HiL_TechDay_Beispiel_08bnd.c HiL_TechDay_Beispiel_09alg.c HiL_TechDay_Beispiel_10asr.c HiL_TechDay_Beispiel_11mix.c HiL_TechDay_Beispiel_12jac.c HiL_TechDay_Beispiel_13opt.c HiL_TechDay_Beispiel_14lnz.c \
HiL_TechDay_Beispiel_15syn.c HiL_TechDay_Beispiel_16dae.c HiL_TechDay_Beispiel_17inl.c HiL_TechDay_Beispiel_init_fmu.c
OFILES=$(CFILES:.c=.o)
GENERATEDFILES=$(MAINFILE) HiL_TechDay_Beispiel_FMU.makefile HiL_TechDay_Beispiel_literals.h HiL_TechDay_Beispiel_model.h HiL_TechDay_Beispiel_includes.h HiL_TechDay_Beispiel_functions.h  HiL_TechDay_Beispiel_11mix.h HiL_TechDay_Beispiel_12jac.h HiL_TechDay_Beispiel_13opt.h HiL_TechDay_Beispiel_init_fmu.c HiL_TechDay_Beispiel_info.c $(CFILES) HiL_TechDay_Beispiel_FMU.libs

# FIXME: before you push into master...
RUNTIMEDIR=include
OMC_MINIMAL_RUNTIME=1
OMC_FMI_RUNTIME=1
include $(RUNTIMEDIR)/Makefile.objs
ifneq ($(NEED_RUNTIME),)
RUNTIMEFILES=$(FMI_ME_OBJS:%=$(RUNTIMEDIR)/%.o)
endif

PHONY: HiL_TechDay_Beispiel_FMU
HiL_TechDay_Beispiel_FMU: nozip
    cd .. && rm -f ../HiL_TechDay_Beispiel.fmu && zip -r ../HiL_TechDay.Beispiel.fmu *
nozip: $(MAINOBJ) HiL_TechDay_Beispiel_functions.h HiL_TechDay_Beispiel_literals.h $(OFILES) $(RUNTIMEFILES)
    $(CXX) -shared -I. -o HiL_TechDay_Beispiel$(DLLEXT) $(MAINOBJ) $(RUNTIMEFILES) $(OFILES) $(CPPFLAGS) -L"C:/Users/trari/Documents/HiL_TechDay"   $(CFLAGS) $(LDFLAGS) -llis -Wl,--kill-at
    mkdir.exe -p ../binaries/win64
    dlltool -d HiL_TechDay_Beispiel.def --dllname HiL_TechDay_Beispiel$(DLLEXT) --output-lib HiL_TechDay_Beispiel.lib --kill-at
    cp HiL_TechDay_Beispiel$(DLLEXT) HiL_TechDay_Beispiel.lib HiL_TechDay_Beispiel_FMU.libs ../binaries/win64/
    rm -f *.o HiL_TechDay_Beispiel$(DLLEXT) $(OFILES) $(RUNTIMEFILES)
    cd .. && rm -f ../HiL_TechDay_Beispiel.fmu && zip -r ../HiL_TechDay.Beispiel.fmu *

Edited by: Arinomo23 - Mar-01-19 07:21:34

Re: undefined reference to fmi2 functions

Hallo DarioMangoni,

just an update, in case you are interested. The problem on the first post is solved by adding

Code:

#define FMI2_FUNCTION_PREFIX ModelName_

in the ModelName_FMU.c

some how the its not defined by default.

And a lot of

Code:

 #include "File" 

in the ModelName_model.h  and ModelName_FMU.c that are incorrect, because all the functions is now under

Code:

 source/include 

now i got a bunch more undefined reference (Hooray!!). i think i have to manually link every file.c that is needed by my model because it is not declared in the xml file.

Cheers

Edited by: Arinomo23 - Feb-28-19 12:22:25

Re: undefined reference to fmi2 functions

I would suggest to NOT follow this way...
Tweaking the source code generated by OpenModelica:
- could be quite a pain in the ass
- if you have problem with linking, it's quite probable you are going to mess up things more;
- you may not know some reasons why OpenModelica programmers did what they did

I will definitely go with explicit dynamic linking, that I can assure it does work.

Re: undefined reference to fmi2 functions

I would strongly suggest using the provided configure script and makefiles inside the FMU. The Makefile will contain things like:

Code:

override CPPFLAGS += -Iinclude/ -Iinclude/fmi2 -I.    -DOMC_MODEL_PREFIX=M -DOMC_NUM_MIXED_SYSTEMS=0 -DOMC_NUM_LINEAR_SYSTEMS=0 -DOMC_NUM_NONLINEAR_SYSTEMS=0 -DOMC_NDELAY_EXPRESSIONS=0 -DOMC_NVAR_STRING=0

Which is different for different generated models. Note that the makefiles listed above says the prefix is KS_TA_HiL_Internal_SignalScaling, but the linking error has a different expected name...

Also note that you have -Wl,--output-def=KS_TA_HiL_Internal_SignalScaling.def in CPPFLAGS, which are preprocessor flags. It is a linker flag and might not be present when linking since it's not in LDFLAGS.

Re: undefined reference to fmi2 functions

Hallo,

thanks for the feedback.

sjoelund.se wrote:


Which is different for different generated models. Note that the makefiles listed above says the prefix is KS_TA_HiL_Internal_SignalScaling, but the linking error has a different expected name...

I'm sorry, I copied the wrong makefile. I have edited my post so its consistent

sjoelund.se wrote:


Also note that you have -Wl,--output-def=KS_TA_HiL_Internal_SignalScaling.def in CPPFLAGS, which are preprocessor flags. It is a linker flag and might not be present when linking since it's not in LDFLAGS.

Referring to thread in

Code:

 https://openmodelica.org/forum/default-topic/2382-link-to-fmu-models 

could this be one of the reason of linking problem? at first i thought it could be one of the resons, but accoring to dSpace, since the "Source" tags is missing in the xml file,  ConfigurationDesk will ignore the binaries and try to compile directly from the source file. So maybe thats that.

The workaround of adding

Code:

 #define FMI2_FUNCTION_PREFIX Modelname_ 

is suggested by dSpace. Presumably referring to FMI2 Documentation section 2.1.1 page 14 and that's just how they set their automatic code generation for *.a and *.cpp used to build the real-time application. But as DarioMangoni said, it just broke a bunch more links, since now I got 30+ undifined referrence instead of the original 10.

Note that the original error all started with prefix dsfmu_ and referring to dsfmu_*.cpp file, and after the workaround it points to OM files in source folder.

One last question, in the ModelName_FMU.c generated by OMEdit, there one line that said

Code:

 #include "fmu2_model_interface.h 

why was it not

Code:

 #include "include/fmi2/fmu2_model_interface.h" 

Because the header file is in other subdirectory, so i thought this was my problem expalined on the first post and i have to include the

Code:

 FMURoot/source/inlcude/fmi2 

thanks again for the feedback, DarioMangoni and sjoelund.se

cheers

Re: undefined reference to fmi2 functions

Arinomo23 wrote:

why was it not
Code:
#include "include/fmi2/fmu2_model_interface.h"

Because we have multiple ways of compiling the FMU; you can compile against the library and include files in the OpenModelica directory directly in some cases.

Re: undefined reference to fmi2 functions

Okey, thanks. i'll try to see if it is possilbe to use FMU from OMEdit with ConfigDesk from dSpace.

Do you have, by any chance, an information regarding implementation of OM's FMU for real-time test/HiL test?

Re: undefined reference to fmi2 functions

That's up to the FMU importer to implement. OMSimulator had some experimental real-time synchronization before its API changed current/smile

Re: undefined reference to fmi2 functions

sjoelund.se wrote:


That's up to the FMU importer to implement. OMSimulator had some experimental real-time synchronization before its API changed current/smile

Okey, thanks for the calrification and good luck for the conference next week.

Re: undefined reference to fmi2 functions

Hi everyone,
I want to import a FMU model for real-time-simulation with dSPACE as well.
I started with a FMU of my friend, which was created in an older version. Also it was for model exchange.
With that I got the following error, like Arinomo.

Code:

fatal error: openmodelica.h: No such file or directory

The OM support suggested to use the newest nightly for the fmi generation since there were some bug fixes.
Also I read in the dSPACE Help, that ConfigurationDesk only supports Co-Simulation.
These are the two things I changed, but I still get some errors when trying to generate code in Configuration Desk.

Code:

Creating application image file ...

dsfmu_mdlfunctions.o86: In function `co_sim_test_DSFMUInitMdl':
dsfmu_mdlfunctions.cpp:(.text+0x5b): undefined reference to `co_sim_test_fmi2Instantiate'
dsfmu_mdlfunctions.o86: In function `co_sim_test_DSFMUStartMdl':
dsfmu_mdlfunctions.cpp:(.text+0x121): undefined reference to `co_sim_test_fmi2SetupExperiment'
dsfmu_mdlfunctions.cpp:(.text+0x153): undefined reference to `co_sim_test_fmi2SetReal'
dsfmu_mdlfunctions.cpp:(.text+0x16d): undefined reference to `co_sim_test_fmi2EnterInitializationMode'
dsfmu_mdlfunctions.cpp:(.text+0x187): undefined reference to `co_sim_test_fmi2ExitInitializationMode'
dsfmu_mdlfunctions.cpp:(.text+0x1e7): undefined reference to `co_sim_test_fmi2GetReal'
dsfmu_mdlfunctions.cpp:(.text+0x219): undefined reference to `co_sim_test_fmi2GetInteger'
dsfmu_mdlfunctions.cpp:(.text+0x24b): undefined reference to `co_sim_test_fmi2GetBoolean'
dsfmu_mdlfunctions.cpp:(.text+0x5c9): undefined reference to `co_sim_test_fmi2Reset'
dsfmu_mdlfunctions.o86: In function `co_sim_test_DSFMUStep':
dsfmu_mdlfunctions.cpp:(.text+0x64e): undefined reference to `co_sim_test_fmi2SetReal'
dsfmu_mdlfunctions.cpp:(.text+0x698): undefined reference to `co_sim_test_fmi2DoStep'
dsfmu_mdlfunctions.cpp:(.text+0x6ca): undefined reference to `co_sim_test_fmi2GetReal'
dsfmu_mdlfunctions.o86: In function `co_sim_test_DSFMUProvideInputs':
dsfmu_mdlfunctions.cpp:(.text+0x944): undefined reference to `co_sim_test_fmi2SetReal'
dsfmu_mdlfunctions.o86: In function `co_sim_test_DSFMUGetOutputs':
dsfmu_mdlfunctions.cpp:(.text+0xa34): undefined reference to `co_sim_test_fmi2GetReal'
dsfmu_mdlfunctions.o86: In function `co_sim_test_DSFMUProvideParametersInit':
dsfmu_mdlfunctions.cpp:(.text+0xb34): undefined reference to `co_sim_test_fmi2SetReal'
dsfmu_mdlfunctions.o86: In function `co_sim_test_DSFMUGetDependentParametersInit':
dsfmu_mdlfunctions.cpp:(.text+0xc34): undefined reference to `co_sim_test_fmi2GetReal'
dsfmu_mdlfunctions.cpp:(.text+0xc66): undefined reference to `co_sim_test_fmi2GetInteger'
dsfmu_mdlfunctions.cpp:(.text+0xc98): undefined reference to `co_sim_test_fmi2GetBoolean'
dsfmu_mdlfunctions.o86: In function `co_sim_test_DSFMUStopMdl':
dsfmu_mdlfunctions.cpp:(.text+0xf9c): undefined reference to `co_sim_test_fmi2Terminate'
MotorThermal.Components.MotorModel3d_FMU_CNT.a: In function `co_sim_test_functionInitialEquations':
meta_modelica_catch.c:(.text+0x2f8a32): undefined reference to `co_sim_test_functionInitialEquations_0'
meta_modelica_catch.c:(.text+0x2f8a3e): undefined reference to `co_sim_test_functionInitialEquations_1'
MotorThermal.Components.MotorModel3d_FMU_CNT.a: In function `co_sim_test_functionInitialEquations_lambda0':
meta_modelica_catch.c:(.text+0x389544): undefined reference to `co_sim_test_eqFunction_1'
meta_modelica_catch.c:(.text+0x389550): undefined reference to `co_sim_test_eqFunction_2'
...
...

Since I'm quite new to OpenModelica, I can't understand what the problem is here. So this results in the following questions:
1) Does someone understand what the problem is here and why there are so much unddefined references?
2) Question to Arinomo: Did you solve the problem for your project? If yes, would you share the workaraound with me/us please?

Best regards
Philipp

Re: undefined reference to fmi2 functions

Hallo Philipp,

yes, please use the newest nightly build since it included the necessary c-files in modelDescription.xml. You have to export the FMU as FMU2.0 Co-Simulation. I don't think the static/dynamic linking is necessary since (as far as i know) ConfigDesk don't use the binary provided by OM but i always choose static linking anyway current/big_smile

glow wrote:

Question to Arinomo: Did you solve the problem for your project? If yes, would you share the workaraound with me/us please?

There are some MACROS that need to be defined before you compiled the RT-App in ConfigDesk.

The error you got is due to a missing FMI2_FUNCTION_PREFIX macro.

You can do that either in ConfigDesk

Code:

 FMI2_FUNCTION_PREFIX=ModelName_ 

or add it in ModelName_FMU.c c-file

Code:

#define FMI2_FUNCTION_PREFIX ModelName_

exported from OM (make more sense when you are working with multiple FMUs in one app).

Next you have to set

Code:

HAVE_MMAP=0

in ConfigDesk (only once per RT-Application).

Last you have to modify the modelDescription.xml file by removing the stopTime in

Code:

 DefaultExperiment startTime="0.0" stopTime="1.0" tolerance="1e-006" 

in every FMU you use.

i think with that steps you can successfully build a rt-app in ConfigDesk.

hope the info help you.

Cheers
A

Edited by: Arinomo23 - Jun-28-19 05:29:27
There are 0 guests and 0 other users also viewing this topic
You are here: