How to compile Lua 5.4.0 as a Mac OS X dynamic library

Sunday, May 24th, 2020 | Dennis D. Spreen | Lua, Mac OS X

This is a tutorial on how to compile Lua 5.4.0 as a Mac OS X dynamic library (liblua.dylib).

This tutorial on how to compile Lua as a Mac OS X dynamic library resulting in a liblua5.4.0.dylib is based on the instructions provided by Adrian Perez – thank you!

1. download and build Lua as stated in the Lua FAQ but force a 64-bit compilation

curl -R -O http://www.lua.org/ftp/lua-5.4.0.tar.gz
tar zxf lua-5.4.0.tar.gz
cd lua-5.4.0
make macosx test MYCFLAGS="-arch x86_64"

2. add a new dynamic build rule to the src/makefile and build the library with

echo 'liblua5.4.0.dylib: $(CORE_O) $(LIB_O)' >> src/makefile
echo -e '\t$(CC) -dynamiclib -o $@ $^ $(LIBS) -arch x86_64 -compatibility_version 5.4.0 -current_version 5.4.0 -install_name @rpath/$@' >> src/makefile
make -C src liblua5.4.0.dylib

See Frameworks and Binding for information about the install_name.
You’re done! You should now have a lua interpreter, a luac compiler and a liblua5.4.0.dylib.

Tags: , , , ,

About Dennis D. Spreen

I'm an avid programmer working on a variety of platforms in a variety of languages with a wide technical interest.

Search

Categories