Skip to content

Commit ddf3968

Browse files
committed
Update warning message to help windows users
1 parent ec2fb7d commit ddf3968

File tree

2 files changed

+33
-6
lines changed

2 files changed

+33
-6
lines changed

README.md

+12-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ This package is composed of two aspects:
2828

2929
### Windows
3030

31-
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`.
31+
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.
3232

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

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

77+
### Notes for Windows Users
78+
79+
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
80+
81+
1. Open a MATLAB window with administrative privileges
82+
2. Run the following command in the MATLAB command window: `!matlab -regserver`
83+
3. Close MATLAB and restart Julia
84+
85+
> [!IMPORTANT]
86+
> The version of MATLAB that is registered must be same that `MATLAB.jl` uses.
87+
7788

7889

7990
## Usage

src/engine.jl

+21-5
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,21 @@ startcmd(flags::AbstractVector{<:AbstractString}) =
1616
# 64 K buffer should be sufficient to store the output text in most cases
1717
const default_output_buffer_size = 64 * 1024
1818

19+
const windows_regserver_warning = """
20+
Failed to start MATLAB engine. If you have/had multiple versions of MATLAB installed, this can happen if you
21+
tried to start a different version of MATLAB in Julia compared to which MATLAB server is registered in Windows.
22+
23+
Steps to resolve this:
24+
25+
1. Register a specific MATLAB version manually as a server, open a MATLAB window as a user with administrator privileges.
26+
In MATLAB, enter the command `!matlab -regserver`. Then close the MATLAB window. More details:
27+
https://de.mathworks.com/help/matlab/matlab_external/registering-matlab-software-as-a-com-server.html
28+
29+
2. Ensure that the MATLAB.jl package is using the same MATLAB version that was registered in step 1. See the instructions on GitHub
30+
on how to change the version that MATLAB.jl uses:
31+
https://github.com/JuliaInterop/MATLAB.jl?tab=readme-ov-file#changing-matlab-version
32+
"""
33+
1934
mutable struct MSession
2035
ptr::Ptr{Cvoid}
2136
buffer::Vector{UInt8}
@@ -27,12 +42,13 @@ mutable struct MSession
2742
end
2843
ep = ccall(eng_open[], Ptr{Cvoid}, (Ptr{UInt8},), startcmd(flags))
2944
if ep == C_NULL
30-
@warn("Confirm MATLAB is installed and discoverable.", maxlog = 1)
45+
@warn(
46+
"Confirm MATLAB is installed and discoverable.",
47+
matlab_libpath,
48+
maxlog = 1
49+
)
3150
if Sys.iswindows()
32-
@warn(
33-
"Ensure `matlab -regserver` has been run in a Command Prompt as Administrator.",
34-
maxlog = 1
35-
)
51+
@warn(windows_regserver_warning, maxlog = 1)
3652
elseif Sys.islinux()
3753
@warn(
3854
"Ensure `csh` is installed; this may require running `sudo apt-get install csh`.",

0 commit comments

Comments
 (0)