# findMatlab.cmake mex not found in Windows 10

**URL:** https://discourse.cmake.org/t/findmatlab-cmake-mex-not-found-in-windows-10/5201
**Category:** Usage
**Tags:** os:windows
**Created:** [March 11, 2022, 7:39am UTC](https://discourse.cmake.org/t/findmatlab-cmake-mex-not-found-in-windows-10/5201 "2022-03-11T07:39:50Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![plitkey](https://discourse.cmake.org/user_avatar/discourse.cmake.org/plitkey/32/2254_2.png) [@plitkey](https://discourse.cmake.org/u/plitkey)
#### Post date: [March 11, 2022, 7:39am UTC](https://discourse.cmake.org/t/findmatlab-cmake-mex-not-found-in-windows-10/5201/1 "2022-03-11T07:39:50Z")

</div>

I have CMake version 3.23.0-rc1 installed with installer and I have problems with findMatlab. I have copied latest version of findMatlab.cmake from github, but still the same error remains:

CMake Error at C:/Program Files/CMake/share/cmake-3.23/Modules/FindPackageHandleStandardArgs.cmake:230 (message):  
Could NOT find Matlab (missing: Matlab\_MEX\_LIBRARY Matlab\_MX\_LIBRARY)  
(found version “9.11”)  
Call Stack (most recent call first):  
C:/Program Files/CMake/share/cmake-3.23/Modules/FindPackageHandleStandardArgs.cmake:594 (\_FPHSA\_FAILURE\_MESSAGE)  
C:/Program Files/CMake/share/cmake-3.23/Modules/FindMatlab.cmake:1946 (find\_package\_handle\_standard\_args)  
CMakeLists.txt:27 (find\_package)

I am trying to compile a mex file with MinGW compiler, the mex library is in extern\lib\win64\mingw64\libmex.lib  
the header file mex.h is in extern\include\mex.h  
Maybe the Matlab\_EXTERN\_BINARIES\_DIR is not currently correctly set?

Printed out some variables and It seems that \_matlab\_64Build variable is not correctly set. EXTERN\_LIBRARY\_DIR is set to extern/lib/win32.

It turns out the problem was user stupidity - I had path to MinGW32 compiler set in environment variables and was causing the mixup myself. Business as usual.

I have no problems in linux and absolutely love the matlab\_add\_mex function this findMatlab provides. It would be perfect if it would work in Windows also.

Br. Paula

---

<div class="post-metadata">

### Author: ![plitkey](https://discourse.cmake.org/user_avatar/discourse.cmake.org/plitkey/32/2254_2.png) [@plitkey](https://discourse.cmake.org/u/plitkey)
#### Post date: [March 11, 2022, 11:31am UTC](https://discourse.cmake.org/t/findmatlab-cmake-mex-not-found-in-windows-10/5201/2 "2022-03-11T11:31:19Z")

</div>

Well I could switch the compiler to MinGW64, but the findMatlab sets the path using CMAKE\_SIZEOF\_VOID\_P and it seems the size is 4 because the path still gets set to extern/lib/win32.

---

<div class="post-metadata">

### Author: ![jtxa](https://discourse.cmake.org/user_avatar/discourse.cmake.org/jtxa/32/1535_2.png) [@jtxa](https://discourse.cmake.org/u/jtxa)
#### Post date: [March 12, 2022, 11:02am UTC](https://discourse.cmake.org/t/findmatlab-cmake-mex-not-found-in-windows-10/5201/3 "2022-03-12T11:02:41Z")

</div>

For using Matlab you need to have a working 64-bit compiler first.  
If `CMAKE_SIZEOF_VOID_P` is still 4, then you had set up MinGW64 to cross-compiler for 32-bit Windows. Or you simply forgot to remove your cache file after switching compilers.

---

<div class="post-metadata">

### Author: ![plitkey](https://discourse.cmake.org/user_avatar/discourse.cmake.org/plitkey/32/2254_2.png) [@plitkey](https://discourse.cmake.org/u/plitkey)
#### Post date: [March 14, 2022, 9:02am UTC](https://discourse.cmake.org/t/findmatlab-cmake-mex-not-found-in-windows-10/5201/4 "2022-03-14T09:02:44Z")

</div>

Thanks! I had messed up and had several versions of mingw and thought “MinGW” is 64 bit. After selecting “mingw-64” findMatlab works just fine 👌.
