cannot open file 'Ruby.lib' and issues with FindRuby.cmake
System: CMake 3.24.0-rc1 Windows 10 Visual Studio 17 2022 Ruby 3.1.2
I'm having issues with including ruby in my project using
#include <ruby.h>
The initial error I was having was getting CMake to find Ruby on my system:
CMake Error at C:/Program Files/CMake/share/cmake-3.24/Modules/FindPackageHandleStandardArgs.cmake:230 (message):
Could NOT find Ruby (missing: Ruby_LIBRARY) (found suitable exact version
"3.1.2")
Call Stack (most recent call first):
C:/Program Files/CMake/share/cmake-3.24/Modules/FindPackageHandleStandardArgs.cmake:594 (_FPHSA_FAILURE_MESSAGE)
C:/Program Files/CMake/share/cmake-3.24/Modules/FindRuby.cmake:509 (FIND_PACKAGE_HANDLE_STANDARD_ARGS)
Looking through the FindRuby.cmake
file I found that CMake was looking for a lib filename pattern (_Ruby_POSSIBLE_LIB_NAMES
) that didn't match the one in my Ruby binary directory
x64-ucrt-ruby310.dll
In my CMakeCache file I found that adding the Ruby library manually worked so I first cleared the build directory and then set the Ruby_LIBRARY in the CMakeLists.txt file
set(Ruby_LIBRARY "C:/foo/bar/ruby/bin/x64-ucrt-ruby310.dll")
I was then able to successfully build the file
-- Selecting Windows SDK version 10.0.19041.0 to target Windows 10.0.19044.
-- Found Ruby: C:/foo/bar/Ruby31-x64/bin/ruby.exe (found suitable exact version "3.1.2")
-- Configuring done
-- Generating done
However when attempting to create an exe I get the following error which I am unsure how to resolve
LINK : fatal error LNK1104: cannot open file 'Ruby.lib'
I found a similar issue to mine #21066 (closed) but after both following the steps above and the steps outlined in that issue, I still have the link issue.