From: miettinen Date: Fri, 16 May 2014 10:51:17 +0000 (+0000) Subject: Loading fortran and msvc libraries for Sysdyn (needed by OpenModelica), also in game... X-Git-Tag: 1.8.1~59 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=ab1b1c90fc6efbb2fa5c9c324cdf78937437a36a;p=simantics%2Fsysdyn.git Loading fortran and msvc libraries for Sysdyn (needed by OpenModelica), also in game experiment. FMU libraries compiled with msvc2010. (refs #4794) git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@29502 ac1ea38d-2e2b-0410-8846-a27921b304fc --- diff --git a/org.simantics.fmu.me.win32/libraries/FMUSimulator.dll b/org.simantics.fmu.me.win32/libraries/FMUSimulator.dll index cee79fe9..6db0c3f5 100644 Binary files a/org.simantics.fmu.me.win32/libraries/FMUSimulator.dll and b/org.simantics.fmu.me.win32/libraries/FMUSimulator.dll differ diff --git a/org.simantics.fmu.me.win32/libraries/miniunz.dll b/org.simantics.fmu.me.win32/libraries/miniunz.dll index a218a76b..312a60bb 100644 Binary files a/org.simantics.fmu.me.win32/libraries/miniunz.dll and b/org.simantics.fmu.me.win32/libraries/miniunz.dll differ diff --git a/org.simantics.fmu.me.win32/libraries/zlibwapi.dll b/org.simantics.fmu.me.win32/libraries/zlibwapi.dll index bd6d8276..fa494119 100644 Binary files a/org.simantics.fmu.me.win32/libraries/zlibwapi.dll and b/org.simantics.fmu.me.win32/libraries/zlibwapi.dll differ diff --git a/org.simantics.modelica/src/org/simantics/modelica/ModelicaManager.java b/org.simantics.modelica/src/org/simantics/modelica/ModelicaManager.java index 7908c7f9..ae40d665 100644 --- a/org.simantics.modelica/src/org/simantics/modelica/ModelicaManager.java +++ b/org.simantics.modelica/src/org/simantics/modelica/ModelicaManager.java @@ -127,10 +127,15 @@ public class ModelicaManager { File mbin = new File(mingw, "bin"); File mlib = new File(mingw, "lib"); - env.put("PATH", env.get("PATH") + File.pathSeparator + bin.getAbsolutePath() - + File.pathSeparator + mbin.getAbsolutePath() - + File.pathSeparator + mlib.getAbsolutePath()); - + String path_allcaps = env.get("PATH") == null ? "" : env.get("PATH") + File.pathSeparator; + env.put("PATH", path_allcaps + bin.getAbsolutePath() + + File.pathSeparator + mbin.getAbsolutePath() + + File.pathSeparator + mlib.getAbsolutePath()); + String path = env.get("Path") == null ? "" : env.get("Path") + File.pathSeparator; + env.put("Path", path + bin.getAbsolutePath() + + File.pathSeparator + mbin.getAbsolutePath() + + File.pathSeparator + mlib.getAbsolutePath()); + env.put("MODELICAUSERCFLAGS", "-O0"); // run the process diff --git a/org.simantics.sysdyn.feature/rootfiles/msvcr100.dll b/org.simantics.sysdyn.feature/rootfiles/msvcr100.dll new file mode 100644 index 00000000..3e82b1ae Binary files /dev/null and b/org.simantics.sysdyn.feature/rootfiles/msvcr100.dll differ diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynGameExperiment.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynGameExperiment.java index 36b13025..ced8ad76 100644 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynGameExperiment.java +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynGameExperiment.java @@ -16,6 +16,7 @@ import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; +import java.lang.reflect.Field; import java.util.ArrayList; import java.util.HashMap; @@ -64,6 +65,7 @@ public class SysdynGameExperiment extends OldSysdynExperiment { private double startTime = DEFAULT_START_TIME; private double stepDuration = DEFAULT_STEP_DURATION; private int savePer = 1; + private static boolean fortranLibrariesLoaded = false; public static double DEFAULT_STEP_DURATION = 1.0; public static double DEFAULT_STEP_LENGTH = 0.1; @@ -243,11 +245,45 @@ public class SysdynGameExperiment extends OldSysdynExperiment { if(simulationLocation != null && !canceled) { // Load fmu and initialize it for simulation try { + if (!fortranLibrariesLoaded) { + File omDir = ModelicaManager.getOMHome(); + File mingw = new File(omDir, "MinGW"); + File mbin = new File(mingw, "bin"); + + // Add MinGW path to java.library.path. This is a bit of a hack because + // java.library.path isn't intended to be set programmatically. + String newLibPath = System.getProperty("java.library.path") + File.pathSeparator + mbin.getAbsolutePath(); + System.setProperty("java.library.path", newLibPath); + Field fieldSysPath = ClassLoader.class.getDeclaredField("sys_paths"); + fieldSysPath.setAccessible(true); + if (fieldSysPath != null) { + fieldSysPath.set(System.class.getClassLoader(), null); + } + + System.loadLibrary("libgfortran-3"); + System.out.println("Loaded libgfortran-3.dll"); + System.loadLibrary("pthreadGC2"); + System.out.println("Loaded pthreadGC2.dll"); + fortranLibrariesLoaded = true; + } + control.loadFMUFile(simulationLocation.executableFile.getAbsolutePath()); // unzip and load fmu instantiate(); } catch (FMUJNIException e) { System.err.println("SysdynGameExperiment initialization failed:\n\t" + e.getMessage()); + } catch (SecurityException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (NoSuchFieldException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalArgumentException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalAccessException e) { + // TODO Auto-generated catch block + e.printStackTrace(); } }