lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Hi,

On 19.07.21 17:19, Hugo Musso Gualandi wrote:
> 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 only want to compile the ".c" to an
> ".so". I don't want to at the same time install the ".so" as a Luarocks package.

Sorry, I don't know a simple tool for this, but if I just want to compile a
simple Lua-Module I'm always ending in the following solution (because this is
the simplest way for me, I found so far):

Use the same (similar) toolchain on all platforms, this would be the GNU based
build tools:

1.) Linux: already included in distributions
2.) Windows: MSYS2 (https://www.msys2.org/)
3.) Mac OS:  brew (https://brew.sh/)

Example commands for limath:
=============================
# All platforms:
wget https://web.tecgraf.puc-rio.br/~lhf/ftp/lua/ar/limath-103.tar.gz
tar xzf limath-103.tar.gz
cd limath-103

# Linux:
INC=/usr/include/lua
EXT=so
ADD=

# Windows in MINGW64 shell:
INC=/mingw64/include/
EXT=dll
ADD=/mingw64/bin/lua54.dll

# MacOS
INC=/usr/local/include/lua
EXT=so
ADD="-undefined dynamic_lookup"

# All platforms:
gcc -shared -fPIC  -I $INC -I src limath.c src/imath.c  $ADD -o imath.$EXT
=============================

Best regards,
Oliver