findMatlab.cmake mex not found in Windows 10

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

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.

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.

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 :ok_hand:.