- 1 year ago
Cmake Can´t find luajit packages of msys2 (windows)
When using CMake and MSYS2 on Windows, you may encounter issues with CMake not finding the Luajit packages. This can occur due to the differences in the environment variables and paths used by MSYS2 and CMake. Here are a few steps you can take to resolve this issue:
Ensure MSYS2 Environment Variables are Set: Verify that the necessary MSYS2 environment variables are properly set. These variables include
MSYS2_PATH_TYPE
andMSYS2_CMAKE_GENERATOR
. You can set them in the MSYS2 shell before running CMake or by adding them to your system or user environment variables.Use the Correct Generator: Make sure to use the appropriate CMake generator for MSYS2. You can specify the generator using the
-G
option when running CMake. For example:bashcmake -G "MSYS Makefiles" path/to/source
Update CMake's FindLuajit Module: The CMake
FindLuajit
module might not have the necessary paths configured for MSYS2. You can update theFindLuajit.cmake
module to include the correct paths for Luajit in MSYS2. Here's an example of how you can modify the module:a. Locate the
FindLuajit.cmake
module file in your CMake installation directory or the project's CMake modules directory.b. Open
FindLuajit.cmake
in a text editor and look for the line:cmakeSET(LUA_INCLUDE_DIR_HINTS
${_LUA_INC_HINTS}
/usr/include
/usr/local/include
/opt/local/include
/sw/include
)
c. Add the following path to the
LUA_INCLUDE_DIR_HINTS
list:cmake/mingw64/include
d. Save the modified
FindLuajit.cmake
module file.Specify Luajit Include and Library Directories: If the above steps don't work, you can try manually specifying the Luajit include and library directories in your CMakeLists.txt file. Add the following lines to your CMakeLists.txt:
cmake# Specify the Luajit include directory
include_directories("/mingw64/include/luajit-2.0")
# Specify the Luajit library directory
link_directories("/mingw64/lib")
Adjust the paths if your Luajit installation is located in a different directory.
Clear CMake Cache: If you made changes to the CMake configuration or modified the
FindLuajit
module, make sure to delete the CMake cache (CMakeCache.txt
) before rerunning CMake. This ensures that CMake picks up the updated configuration.
By following these steps, you should be able to resolve the issue of CMake not finding the Luajit packages in MSYS2 on Windows.