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

Who shall define the prefix for source code FMUs? #420

Open
modelica-trac-importer opened this Issue Oct 17, 2018 · 2 comments

Comments

Projects
None yet
3 participants
@modelica-trac-importer

modelica-trac-importer commented Oct 17, 2018

Reported by cbertsch on 5 Jun 2017 15:26 UTC
I have a perhaps naive question regarding the prefixing of FMI-Functions in source code FMUs.

Citing from the FMI 2.0 Standard p.14:

The goal is that both textual and binary representations of FMUs are supported and that several FMUs
might be present at the same time in an executable (for example FMU A may use an FMU B). In order
for this to be possible, the names of the functions in different FMUs must be different or function pointers
must be used. To support the first variant macros are provided in “fmi2Functions.h” to build the actual
function names by using a function prefix that depends on how the FMU is shipped. Typically, FMU
functions are used as follows:
// FMU is shipped with C source code, or with static link library
#define FMI2_FUNCTION_PREFIX MyModel_
#include "fmi2Functions.h"
< usage of the FMU functions >

I am wondering, if the prefix shall be defined in the source code (as I have done it in the reference FMUs now) or by the importing tool in the compile command with something like

cl ... /DFMI2_FUNCTION_PREFIX=MyModel_ source_file.c ...

(Visual Studio specific: (https://msdn.microsoft.com/en-us/library/aa235412%28v=vs.60%29.aspx) or -D for gcc https://gcc.gnu.org/onlinedocs/gcc/Preprocessor-Options.html)

The advantage of this solution would be, that multiple instances of the same source-code FMU could be compiled and that the same C-Code code could also be used to create a dynamic link library (e.g. for a different OS)

Or do I get something wrong?


Migrated-From: https://trac.fmi-standard.org/ticket/420

@modelica-trac-importer

This comment has been minimized.

modelica-trac-importer commented Oct 17, 2018

Comment by andreas.junghanns on 5 Jun 2017 15:31 UTC
I agree that both versions should be possible from the same source code FMU.
We have so far failed to define exactly how this can be accomplished and it takes looking at the sources and figuring it out.

This is something to be clarified/defined for the next standard version.

@KarlWernersson

This comment has been minimized.

Collaborator

KarlWernersson commented Nov 13, 2018

The specification states that the function prefix must be the modelIdentifier in the xml

FMU is shipped with C source code, or with static link library:
The constructed function name is “MyModel_fmi2GetReal”, in other words the function name is
prefixed with the model name and an “”. As FMI2_FUNCTION_PREFIX the “modelIdentifier”
”attribute defined in , or
is used, together with “
” at the end (see sections 3.3.1
and 4.3.1). A simulation environment can therefore construct the relevant function names by
generating code for the actual function call. In case of a static link library, the name of the library is
MyModel.lib on Windows, and libMyModel.a on Linux, in other words the “modelIdentifier”
attribute is used as library name.

This partially contradicts the second options.
For 2.01. i would prefer to leave it as is to be as little intrusive as possible.
If a clarification is needed maybe a recommendation that the source guard defines it
#if !defined FMI2_FUNCTION_PREFIX
#define FMI2_FUNCTION_PREFIX ...
#endif

@KarlWernersson KarlWernersson removed the 2.0.1 label Nov 13, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment