CMake 找不到 MatLab 库,即使检测到 MatLab

CMake couldn't find MatLab libraries, even though MatLab is detected

我一直在尝试构建 BlockFactory,但在尝试构建它时我不断收到以下错误。

PS F:\simconnect-monitor\blockfactory> cmake -S . -B build
-- Selecting Windows SDK version 10.0.17763.0 to target Windows 10.0.19044. 
-- The CXX compiler identification is MSVC 19.16.27045.0 
-- Detecting CXX compiler ABI info 
-- Detecting CXX compiler ABI info - done 
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/BuildTools/VC/Tools/MSVC/14.16.27023/bin/Hostx86/x86/cl.exe - skipped 
-- Detecting CXX compile features 
-- Detecting CXX compile features - done 
-- Could NOT find Matlab (missing: Matlab_MEX_LIBRARY Matlab_MX_LIBRARY ENG_LIBRARY) (found version "9.10") 
CMake Error at C:/Program Files/CMake/share/cmake-3.18/Modules/FindPackageHandleStandardArgs.cmake:165 (message):
    Could NOT find Matlab (missing: Matlab_MEX_LIBRARY Matlab_MX_LIBRARY   MX_LIBRARY) (found version "9.10") 

Call Stack (most recent call first):
   C:/Program Files/CMake/share/cmake-3.18/Modules/FindPackageHandleStandardArgs.cmake:458 (_FPHSA_FAILURE_MESSAGE)
   cmake/FindMatlab.cmake:1873 (find_package_handle_standard_args)
   deps/mxpp/CMakeLists.txt:45 (find_package)

如您所见,已检测到 MatLab,但找不到正确的库。我尝试使用 CMake 3.18.14 和 3.22.3 没有区别。老实说,我现在真的很失落。我已经在 BlockFactory GitHub 中发布了一个问题,但到目前为止,它仍未解决。

所以,我找到了解决方案。我正在使用 VS2017。默认情况下,对于 VS2017,cmake 生成 32 位项目。您必须传递 cmake -A x64 才能将其强制为 64 位项目。但除此之外,我必须强制 finfmatlab.cmake 仅通过将 _matlab_64build 设置为始终为真来查找 64 位库。如果你这样做,请确保你有 64 位 MatLab。

编辑:或者,您可以安装 VS2019,因为它默认为 64 位项目。