-
Notifications
You must be signed in to change notification settings - Fork 175
Description
Hi
When trying to compile a Dymola source FMU together with a Dymola simulation and then link them there are many identical functions that causes link problems. A way to simply solve this is by making sure things are static declared.
Now for the gconstructor for MSVC the constructor has the following hack to force some function calls before main
#define G_DEFINE_CONSTRUCTOR(_func) G_MSVC_CTOR (_func, G_MSVC_SYMBOL_PREFIX)
#define G_MSVC_CTOR(_func,_sym_prefix) \
static void _func(void); \
extern int (* _array ## _func)(void); \
int _func ## _wrapper(void) { _func(); return _array ## _func == NULL; } \
__pragma(comment(linker,"/include:" _sym_prefix # _func "_wrapper")) \
__pragma(section(".CRT$XCU",read)) \
__declspec(allocate(".CRT$XCU")) int (* _array ## _func)(void) = _func ## _wrapper;
As some of these functions aren't static declared i get to problems when both the FMU and the dymola simuation uses modelicaInternal.c
I tried to modify the hack to make it static but it don't seem to work and i cant say I am an expert in this low level mscv hacking.
My workaround was to copy the name pasting of ModelIdentifier from FMI as this for us is only an issue for FMU's for us.
added to gconstructor _MSC_VER >=1500 defined
#ifndef MODEL_IDENTIFIER
#define MODEL_IDENTIFIER
#endif
#define G_Paste(a,b) a ## b
#define G_PasteB(a,b) G_Paste(a,b)
#define G_FullName(name) G_PasteB(MODEL_IDENTIFIER, name)
non _MSC_VER
#define G_FullName(name) name
and then later in ModelicaRandom,c ModelicaInternal.c, modelicaStandardTables.c I modified the use of G_DEFINE_CONSTRUCTOR by inserting the G_FullName macro
G_DEFINE_CONSTRUCTOR(G_FullName(ModelicaInternal_initializeCS))
static void G_FullName(ModelicaInternal_initializeCS)(void) {
InitializeCriticalSection(&cs);
}
G_DEFINE_DESTRUCTOR(G_FullName(ModelicaInternal_deleteCS))
static void G_FullName(ModelicaInternal_deleteCS)(void) {
DeleteCriticalSection(&cs);
}
If anyone has a better solution i am al ears, otherwise i am happy to make a pull request