Page 1 of 1

How to add a C library in linux?

Posted: Mon Aug 28, 2023 7:01 pm
by pocoyo
Hi everyone.
I'm trying to add a library to the Love2D source code. (The main goal is to expose it as a module on lua). In Windows it was easy using vcpkg, just #include'ing the library compiled and worked.
However in Ubuntu the compilation throw errors, as it is not finding the library functions. In gcc I would use the flag -llibname to make it know about the library. It seems I would need to edit the CMakeList.txt file, however I'm a total noob on cmake.
How could I do that?
Thanks in advance!

Re: How to add a C library in linux?

Posted: Mon Aug 28, 2023 11:15 pm
by zorg
Do you need to modify löve itself though? Can you not just require in the c library?

Re: How to add a C library in linux?

Posted: Tue Aug 29, 2023 1:35 am
by pocoyo
You mean, like in this tutorial? I guess so. I thought it would be faster to have the code directly in the executable. The library contains functions specific to a hardware platform.

Re: How to add a C library in linux?

Posted: Tue Aug 29, 2023 2:01 am
by slime
There won't be a difference, performance-wise. It generally takes more effort to modify love instead of having a standalone library, so the former is slower to implement.

If runtime performance is really important, you'd probably want to use LuaJIT's FFI to call C functions that are in your standalone library instead of creating C bindings with stock Lua's C API. It will be a lot faster when the surrounding code is able to be JIT-compiled.