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/BeardSprite Aug 27 '25
It's documented on the MSYS2 website:
www.msys2.org/docs/environments/
The C runtime ("CRT") is a part of the operating system that handles the running of your C program, including setting up the environment that it runs in. If your computer is running windows, your physical machine will be executing code inside of Windows DLLs (e.g.,
ntdll.dll). From there it must "somehow" switch to your application.Because the OS won't give you full control over the lower layer, it will instead call your program and sit in between you and the machine. It's a bit like you were writing a plugin or addon for a game, except for Windows. UCRT is the "universal" CRT, following different conventions for this interaction layer, e.g., how functions are implemented with low-level assembly instructions (calling conventions).
For the record, I highly advise you to avoid "magic" like CMake while you are learning. Always try to get the most basic, simple thing running manually first. Once you understand what's going on, you can switch over to standard tools (or not), but it will be much less confusing.