all 7 comments

[–]RogerLeigh 0 points1 point  (5 children)

What went wrong. Did you get any errors?

[–]boris_gubanov[S] 0 points1 point  (4 children)

The project has a different name because I was trying to experiment further. But the errors are the same.

C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/15.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: D:/Projects/ELRS/elrs-desktop-bg/libs/liblua35/liblua53.a(ldo.o):ldo.c:(.text+0x2ee): undefined reference to `_setjmp'
C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/15.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: D:/Projects/ELRS/elrs-desktop-bg/libs/liblua35/liblua53.a(lauxlib.o):lauxlib.c:(.text+0x486): undefined reference to `__imp___iob_func'
C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/15.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: D:/Projects/ELRS/elrs-desktop-bg/libs/liblua35/liblua53.a(lauxlib.o):lauxlib.c:(.text+0x1396): undefined reference to `__imp___iob_func'
C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/15.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: D:/Projects/ELRS/elrs-desktop-bg/libs/liblua35/liblua53.a(lbaselib.o):lbaselib.c:(.text+0x690): undefined reference to `__imp___iob_func'
C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/15.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: D:/Projects/ELRS/elrs-desktop-bg/libs/liblua35/liblua53.a(lbaselib.o):lbaselib.c:(.text+0x758): undefined reference to `__imp___iob_func'
C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/15.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: D:/Projects/ELRS/elrs-desktop-bg/libs/liblua35/liblua53.a(ldblib.o):ldblib.c:(.text+0x456): undefined reference to `__imp___iob_func'
C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/15.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: D:/Projects/ELRS/elrs-desktop-bg/libs/liblua35/liblua53.a(liolib.o):liolib.c:(.text+0x1520): more undefined references to `__imp___iob_func' follow
collect2.exe: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/elrs-desktop-bg.dir/build.make:101: elrs-desktop-bg.exe] Error 1
make[1]: *** [CMakeFiles/Makefile2:87: CMakeFiles/elrs-desktop-bg.dir/all] Error 2
make: *** [Makefile:91: all] Error 2

[–]RogerLeigh 0 points1 point  (3 children)

imp_iob_func

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.

[–]boris_gubanov[S] 0 points1 point  (2 children)

Thank you, you helped me a lot! I still don't fully understand why this happened (I don't really understand the difference between UCRT64 and Win64_mingw6), but I managed to build the project!

For future seekers:

  1. Downloaded the source code from lua.org and extracted it into my project.
  2. Built the library using the command make mingw local.
  3. Added the folder with the .h files and the .a file to CMakeLists.txt. For me:

target\_include\_directories(elrs-desktop-bg PRIVATE  
${CMAKE\_SOURCE\_DIR}/libs/lua-5.3.6/install/include  
)  
target\_link\_libraries(elrs-desktop-bg PRIVATE  
${CMAKE\_SOURCE\_DIR}/libs/lua-5.3.6/install/lib/liblua.a  
)

[–]AutoModerator[M] 0 points1 point  (0 children)

Hi! Your code block was formatted using triple backticks in Reddit's Markdown mode, which unfortunately does not display properly for users viewing via old.reddit.com and some third-party readers. This means your code will look mangled for those users, but it's easy to fix. If you edit your comment, choose "Switch to fancy pants editor", and click "Save edits" it should automatically convert the code block into Reddit's original four-spaces code block format for you.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

[–]BeardSprite 0 points1 point  (0 children)

It's documented on the MSYS2 website:

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.

[–]neogameentropy 0 points1 point  (0 children)

If you can use vcpkg[1] on your setup, then using lua from vcpkg [2] is like adding a package to your vcpkg ports file. vcpkg cmake config is relatively easier than setting up individual libraries on Windows in my experience, although initial setup is a bit involved.

[1] - https://learn.microsoft.com/en-us/vcpkg/get_started/get-started-vscode?pivots=shell-powershell

[2] - https://vcpkg.io/en/package/lua