Skip to content

Commit 3b5ade5

Browse files
committed
- fix #2989 (build shared compiler on Windows)
* on Windows compile the main inside the lib so that all globals are used from the dll (as in Windows the process and the loaded dll DO NOT SHARE the same global data) git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@23420 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
1 parent 2a7043f commit 3b5ade5

File tree

2 files changed

+44
-8
lines changed

2 files changed

+44
-8
lines changed

Compiler/Template/CodegenC.tpl

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11203,6 +11203,24 @@ let name = ("omc_" + underscorePath(entryPoint))
1120311203
<<
1120411204
/* This is an automatically generated entry point to a MetaModelica function */
1120511205

11206+
#if defined(__cplusplus)
11207+
extern "C" {
11208+
#endif
11209+
11210+
#if defined(OMC_ENTRYPOINT_STATIC)
11211+
11212+
#include <stdio.h>
11213+
#include <openmodelica.h>
11214+
11215+
DLLImport int __omc_main(int argc, char **argv);
11216+
11217+
int main(int argc, char **argv)
11218+
{
11219+
return __omc_main(argc, argv);
11220+
}
11221+
11222+
#else
11223+
1120611224
#include <meta/meta_modelica.h>
1120711225
#include <stdio.h>
1120811226
extern void <%name%>(threadData_t*,modelica_metatype);
@@ -11226,7 +11244,7 @@ static int rml_execution_failed()
1122611244
return 1;
1122711245
}
1122811246

11229-
int main(int argc, char **argv)
11247+
DLLExport int __omc_main(int argc, char **argv)
1123011248
{
1123111249
MMC_INIT();
1123211250
{
@@ -11245,6 +11263,13 @@ int main(int argc, char **argv)
1124511263
EXIT(0);
1124611264
return 0;
1124711265
}
11266+
11267+
#endif
11268+
11269+
#if defined(__cplusplus)
11270+
} /* end extern "C" */
11271+
#endif
11272+
1124811273
>>
1124911274
end generateEntryPoint;
1125011275

Compiler/boot/Makefile.common

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -95,21 +95,32 @@ $(GEN_DIR)%.stamp:
9595
$(GEN_DIR)_main.c:
9696
$(OMC) GenerateEntryPoint.mos
9797

98-
$(OMHOME)/lib/omc/libOpenModelicaCompiler$(SHREXT): $(ALL_OBJECTS) $(OMHOME)/lib/omc/libomcruntime.a $(OMHOME)/lib/omc/libomparse.a
98+
$(GEN_DIR)_main.o: $(GEN_DIR)_main.c
99+
$(CC) -DOMC_ENTRYPOINT_STATIC= -c $(GEN_DIR)_main.c -o $(GEN_DIR)_main.o $(CFLAGS) $(CPPFLAGS)
100+
101+
$(GEN_DIR)_main_omc.c: $(GEN_DIR)_main.c
102+
cp -a $^ $@
103+
104+
$(GEN_DIR)_main_omc.o: $(GEN_DIR)_main_omc.c
105+
$(CC) -c $(GEN_DIR)_main_omc.c -o $(GEN_DIR)_main_omc.o $(CFLAGS) $(CPPFLAGS)
106+
107+
$(OMHOME)/lib/omc/libOpenModelicaCompiler$(SHREXT): $(ALL_OBJECTS) $(OMHOME)/lib/omc/libomcruntime.a $(OMHOME)/lib/omc/libomparse.a $(GEN_DIR)_main_omc.o
99108
@test ! -z "`echo $(ALL_OBJECTS)`" || (echo Empty dependencies for $@ ; false)
100-
$(CC) -shared $(RPATH) $(INSTALL_NAME) -o $@ $^ $(LDFLAGS)
101-
ifeq ($(STATIC),)
109+
$(CC) -shared $(RPATH) $(INSTALL_NAME) -o $@ $^ $(LDFLAGS)
102110

103-
$(GEN_DIR)omc$(EXE_EXT): $(OMHOME)/lib/omc/libOpenModelicaCompiler$(SHREXT) $(GEN_DIR)_main.o
111+
ifeq ($(STATIC),)
112+
#shared
113+
$(GEN_DIR)omc$(EXE_EXT): $(OMHOME)/lib/omc/libOpenModelicaCompiler$(SHREXT) $(GEN_DIR)_main_omc.o $(GEN_DIR)_main.o
104114
$(CC) $(GEN_DIR)_main.o $(RPATH) $(CFLAGS) $(CPPFLAGS) -o $@ $(LDFLAGS) -lOpenModelicaCompiler
105115
install: $(GEN_DIR)omc$(EXE_EXT)
106116
cp -a $< $(OMHOME)/bin/
117+
cp -a $(OMHOME)/lib/omc/libOpenModelicaCompiler$(SHREXT) $(OMHOME)/bin/
107118

108119
else
109-
110-
$(GEN_DIR)omc$(EXE_EXT): $(ALL_OBJECTS) $(GEN_DIR)_main.o $(OMHOME)/lib/omc/libomcruntime.a $(OMHOME)/lib/omc/libomparse.a
120+
#static
121+
$(GEN_DIR)omc$(EXE_EXT): $(ALL_OBJECTS) $(GEN_DIR)_main.o $(GEN_DIR)_main_omc.o $(OMHOME)/lib/omc/libomcruntime.a $(OMHOME)/lib/omc/libomparse.a
111122
@test ! -z "`echo $(ALL_OBJECTS)`" || (echo Empty dependencies for $@ ; false)
112-
$(CC) $(GEN_DIR)_main.o $(RPATH) $(CFLAGS) $(CPPFLAGS) -o $@ $(ALL_OBJECTS) $(LDFLAGS)
123+
$(CC) $(GEN_DIR)_main.o $(RPATH) $(CFLAGS) $(CPPFLAGS) -o $@ $(GEN_DIR)_main_omc.o $(ALL_OBJECTS) $(LDFLAGS)
113124
install: $(GEN_DIR)omc$(EXE_EXT)
114125
cp -a $(GEN_DIR)omc$(EXE_EXT) $(OMHOME)/bin/
115126

0 commit comments

Comments
 (0)