Skip to content

Select one of several installed OpenModelica versions - #33

Merged
adrpo merged 2 commits into
OpenModelica:masterfrom
adrpo:omhome-version
Nov 19, 2026
Merged

adrpo merged 2 commits into
OpenModelica:masterfrom
adrpo:omhome-version

Conversation

@adrpo

@adrpo adrpo commented Nov 17, 2026 •

Copy link
Copy Markdown
Member

Client part of OpenModelica/OpenModelica#5809 (several OpenModelica versions installed side by side on Windows).

With OpenModelica/OpenModelicaSetup#96 the Windows installer keeps OPENMODELICAHOME for the version selected as the default one and sets OPENMODELICAHOME_<version> for each installed version, with every character of the version that is not a letter or a digit replaced by an underscore, e.g. OPENMODELICAHOME_1_27_0.

What changes

The constructor takes the version as a second argument:

omc = OMMatlab('', '1.27.0');   % exactly this version
omc = OMMatlab('', '1.27');     % the newest installed 1.27.x
OMMatlab.installedVersions()    % what is installed, newest first

OpenModelica is looked for in this order:

  1. the omcpath argument
  2. the version argument; an error with the list of the installed versions if it is not installed
  3. on Windows, OPENMODELICAHOME
  4. on Windows, the newest OPENMODELICAHOME_<version>
  5. omc from the PATH

"Newest" compares the numbers of the version: for the same major.minor.patch a pre-release build (1.28.0-dev-…) is older than the release, which is older than a build after it (1.27.0-5-g…). The same order and rules are used in OpenModelica/OMPython#490.

Two fixes that come with it:

  • The session remembers its installation directory and simulate() and linearize() take the DLL path on Windows from it. They used OPENMODELICAHOME, which is the wrong installation for a session started with omcpath (and now with version).
  • On Windows without OPENMODELICAHOME, omc from the PATH is started; before, the command was /bin/omc.exe.

Linux and macOS start omc from the PATH as before unless omcpath or version is given.

Testing

Not run in MATLAB, I have none available. The lookup functions (versionEnvName, versionSortKey, installedVersions, locateOMHome) were run in GNU Octave 10.3 on Linux, loading this OMMatlab.m: 28 checks with directories that contain an empty bin/omc.exe (exact version, start of a version, version that is not installed, default, uninstalled default, newest, real environment variables). The constructor, simulate() and linearize() changes are untested. The PR is taken out of draft on the strength of the Octave run only: a run in MATLAB on Windows (default session, a session with version, simulate() and linearize(), an installation in a directory with a space in its name) is still missing.

The path of omc is now quoted in the Windows START command. Unquoted, an installation in a directory with a space in its name (as the default C:\Program Files\OpenModelica<version> has) is not started: Windows reports that it cannot find the part of the path before the space. That was seen with the same command in OpenModelica/OMOctave#5 on Windows 11, and the quoted command starts omc there; the MATLAB side of it is not run either.


🤖 Generated with Claude Code

The Windows installer is changed to allow several OpenModelica versions
side by side (OpenModelica/OpenModelica#5809,
OpenModelica/OpenModelicaSetup#96). OPENMODELICAHOME then points to the
default one and each version sets OPENMODELICAHOME_<version>, with the
characters of the version that are not letters or digits replaced by
underscores (OPENMODELICAHOME_1_27_0).

OMMatlab(omcpath, version) takes the version as second argument and
looks for OpenModelica in this order:

1. the omcpath argument
2. the version argument: OPENMODELICAHOME_<version>, or the newest
   installed version that starts with it ('1.27' for the newest 1.27.x)
3. on Windows, OPENMODELICAHOME
4. on Windows, the newest OPENMODELICAHOME_<version>
5. omc from PATH

The session remembers its installation directory, and simulate() and
linearize() take the DLL path on Windows from it instead of from
OPENMODELICAHOME, which is the wrong one for a session started with
omcpath or version. On Windows without OPENMODELICAHOME omc from PATH is
started instead of /bin/omc.exe.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The path of omc was passed to START without quotes. With an
installation in a directory with a space in its name, as the default
C:\Program Files\OpenModelica<version> has, Windows reports that it
cannot find the part of the path before the space
(OpenModelica/OpenModelica#5809). Found with the same command in
OMOctave (OpenModelica/OMOctave#5).

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@adrpo
adrpo marked this pull request as ready for review November 19, 2026 07:40
@adrpo
adrpo merged commit 949dae0 into OpenModelica:master Nov 19, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant