Skip to content

Commit

Permalink
Update warning message to help windows users
Browse files Browse the repository at this point in the history
  • Loading branch information
tqml committed Feb 20, 2025
1 parent ec2fb7d commit ddf3968
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 6 deletions.
13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ This package is composed of two aspects:

### Windows

1. For Matlab R2020a onwards, you should be able to go directly to step 2. If you encounter issues, run `matlab -batch "comserver('register')"` in the command prompt. For earlier versions of Matlab, start a command prompt as an administrator and enter `matlab /regserver`.
1. For Matlab R2020a onwards, you should be able to go directly to step 2. If you encounter issues, run `matlab -batch "comserver('register')"` in the command prompt. For earlier versions of Matlab, start a command prompt as an administrator and enter `matlab /regserver`. Alternatively, you can do the same using the MATLAB GUI. To do this, open MATLAB with administrative privileges and run the following command in the MATLAB command window: `!matlab -regserver`. Close MATLAB and restart Julia.

2. From Julia run: `Pkg.add("MATLAB")`

Expand Down Expand Up @@ -74,6 +74,17 @@ If you had the package `MATLAB.jl` already installed and built before changing t
julia> using Pkg; Pkg.build("MATLAB")
```

### Notes for Windows Users

If you are using Windows, MATLAB needs to register its COM interface to properly work with MATLAB.jl. This should happen automatically during installation, but if you encounter issues, you can manually re-register MATLAB (with the version you want to use). To do this

1. Open a MATLAB window with administrative privileges
2. Run the following command in the MATLAB command window: `!matlab -regserver`
3. Close MATLAB and restart Julia

> [!IMPORTANT]
> The version of MATLAB that is registered must be same that `MATLAB.jl` uses.


## Usage
Expand Down
26 changes: 21 additions & 5 deletions src/engine.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,21 @@ startcmd(flags::AbstractVector{<:AbstractString}) =
# 64 K buffer should be sufficient to store the output text in most cases
const default_output_buffer_size = 64 * 1024

const windows_regserver_warning = """
Failed to start MATLAB engine. If you have/had multiple versions of MATLAB installed, this can happen if you
tried to start a different version of MATLAB in Julia compared to which MATLAB server is registered in Windows.
Steps to resolve this:
1. Register a specific MATLAB version manually as a server, open a MATLAB window as a user with administrator privileges.
In MATLAB, enter the command `!matlab -regserver`. Then close the MATLAB window. More details:
https://de.mathworks.com/help/matlab/matlab_external/registering-matlab-software-as-a-com-server.html
2. Ensure that the MATLAB.jl package is using the same MATLAB version that was registered in step 1. See the instructions on GitHub
on how to change the version that MATLAB.jl uses:
https://github.com/JuliaInterop/MATLAB.jl?tab=readme-ov-file#changing-matlab-version
"""

mutable struct MSession
ptr::Ptr{Cvoid}
buffer::Vector{UInt8}
Expand All @@ -27,12 +42,13 @@ mutable struct MSession
end
ep = ccall(eng_open[], Ptr{Cvoid}, (Ptr{UInt8},), startcmd(flags))
if ep == C_NULL
@warn("Confirm MATLAB is installed and discoverable.", maxlog = 1)
@warn(
"Confirm MATLAB is installed and discoverable.",
matlab_libpath,
maxlog = 1
)
if Sys.iswindows()
@warn(
"Ensure `matlab -regserver` has been run in a Command Prompt as Administrator.",
maxlog = 1
)
@warn(windows_regserver_warning, maxlog = 1)
elseif Sys.islinux()
@warn(
"Ensure `csh` is installed; this may require running `sudo apt-get install csh`.",
Expand Down

0 comments on commit ddf3968

Please sign in to comment.