ZED SDK compatibility with MATLAB (error with MEX file)

I am having trouble creating a MEX file for compatibility between ZED SDK and MATLAB. I have been following along with the build procedure outlined in the documentation liked here How to Use Matlab with ZED | Stereolabs

CMake was unable to find the path to MATLAB so I created an environmental variable with the proper path. I thought this would fix the issue but after attempting to configure the file I was given the error displayed in the following in the attached image. I don’t know why it would ignore the environment variable. Any help would be greatly appreciated.

I am using Matlab 2023a along with CUDA 11.6 and ZED SDK 3.8.2 and Visual Studios 17 2022

it looks like cmake is not taking the env var into account.
Can you define it diretcly into the cmake UI? like in this case: Cmake not finding matlab · Issue #23 · stereolabs/zed-matlab · GitHub

In the same time I will check how to fix the cmake to support it directly

Tested, with an env var:

when calling using cmake to generate the project it is directly found and used:

In your case is it really an error or just a warning ?
it looks like you can click en generate? what happens next?

I tried defining it directly and it worked, cmake took the env var when defined directly. It generated fine and could be opened in Visual Stuido. However when built in Visual studios it threw multiple errors and only built 1 out of 2. I tried rebuilding it but to no success. The output from build is listed below.

I will try repeating the entire process from the beginning and if it works ill add an update. Thank you for all your help.

the current master branch is related to the SDK version 4.0 EA.
if you want to use it with a 3.8 version you should pull this: Release V3.8 · stereolabs/zed-matlab · GitHub


I’ve same problem. After solving part of CMake’s links Visual studio will not compile and return me this error:
C1083 Cannot opern include file: ‘mex.h’: No such file or directory mexZED mexZED.cpp 6.

I downloaded package directly from web without any modification.

Thank you in advance!

It looks like you have Matlab related link issues, the file mex.h is within the matlab includes files.

is your cmake looking like this?


yes it looks really similar as you can see.

Do you know how can i solve it?

Thank you in advance,

It looks like your MATLAB_INCLUDE_DIR is wrong.
try to set it to ‘C:/Program Files/MATLAB/R2021b/extern/include’
This folder should contains the file ‘mex.h’, maybe in a new Matlab version (as yours) it has changed

Great, you’ve got the point! Thank you so much, it works! :star_struck: