[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Cross-platform way to compile a Lua module written in C
- From: David Sicilia <dpsicilia@...>
- Date: Mon, 19 Jul 2021 13:46:21 -0400
I think you’ll want to use CMake for this purpose. It has now basically become the de facto cross platform c++ build system (though it does C just the same). It can produce any kind of executable or shared/static library on any platform with a simple and uniform config.
Using it is essentially as simple as:
CMakeLists.txt
—————————
project(C)
find_package(Lua 5.3 REQUIRED)
add_library(mylib SHARED mysource1.c mysource2.c)
target_link_libraries(mylib PUBLIC ${LUA_LIBRARIES})
$ ls
CMakeLists.txt mysource1.c mysource2.c
$ mkdir build
$ cd build
$ cmake ..
$ cmake —build .
There are a few details that I’m sure I left out, so you will have to undoubtedly fiddle with it to make it work, but that’s the basic idea. The thing to keep in mind is that the correct config that you arrive at should be platform independent; cmake should handle all platform specific stuff on its own, when it is used as intended.
David
> Does anyone know if there is some tool that I can use to compile a ".c"
> Lua module to a dynamic library (".so" or ".dll), with all the
> appropriate compilation flags for the operating system?
I believe that GNU "libtool" may address this issue.
But buying into libtool means buying into the entire autoconf/automake
system. I personally can achieve the same effect by getting a brick
and hitting myself in the head with it.
Norman