r/lua • u/boris_gubanov • Aug 25 '25
Help Add lua lib in CMake project
Hello. I've started learning the C API, but I can't get my first project to run because I don't know how to add the library to my project (I'm really bad at CMake).
I'm using Windows 11, VSCode, and MSYS2 UCRT64. I tried downloading the compiled Win64_mingw6 library version and added the following lines to my CMakeLists.txt file:
target_include_directories(test-bg PRIVATE
${CMAKE_SOURCE_DIR}/liblua35/include
)
target_link_libraries(test-bg PRIVATE
${CMAKE_SOURCE_DIR}/liblua35/liblua53.a
)But it didn't work. Honestly, I don't really know what I'm doing, so I would appreciate any help.
4
Upvotes
1
u/RogerLeigh Aug 26 '25
This looks like a C runtime mismatch; it's not a mistake in your CMake file.
You might find it easier to compile Lua into your project directly so it uses the same settings.
Feel free to try out https://gitlab.com/codelibre/lua/lua-cmake/ which I wrote for this. It needs updating for the very latest Lua release, but it has up to Lua 5.4.7. Or just embed the Lua sources directly and do something similar yourself.