fnuecke / eris

Heavy Duty Persistence for Lua 5.2 and 5.3
Other
170 stars 23 forks source link

Help compiling to a .so or .dll file format? #38

Closed Perodactyl closed 1 month ago

Perodactyl commented 1 month ago

I'm testing out Eris currently because I have a distant dream of making a mod which involves minecraft computers (hmm, wonder where that idea comes from...). Currently I'm having trouble compiling to a .so file, any help?

Changes to src/Makefile:

# Makefile for building Lua+Eris, based on the original Lua Makefile.
# See ../doc/readme.html for installation and customization instructions.

# == CHANGE THE SETTINGS BELOW TO SUIT YOUR ENVIRONMENT =======================

# Your platform. See PLATS for possible values.
PLAT= none

CC= gcc -std=gnu99
CFLAGS= -O2 -Wall -Wextra -DLUA_COMPAT_5_2 $(SYSCFLAGS) $(MYCFLAGS)
LDFLAGS= $(SYSLDFLAGS) $(MYLDFLAGS)
LIBS= -lm $(SYSLIBS) $(MYLIBS)

AR= ar rcu
RANLIB= ranlib
RM= rm -f

SYSCFLAGS=
SYSLDFLAGS=
SYSLIBS=

MYCFLAGS=-fPIC
MYLDFLAGS=-shared
MYLIBS=
MYOBJS=eris.o

# == END OF USER SETTINGS -- NO NEED TO CHANGE ANYTHING BELOW THIS LINE =======

Went through this, seems helpful: https://stackoverflow.com/questions/655163/convert-a-static-library-to-a-shared-library

Current issue (trying to seperately combine the .o files to a .so file):

$ gcc -shared -fPIC src/*.o -o lib.so
/usr/bin/ld: src/luac.o: in function `main':
luac.c:(.text.startup+0x0): multiple definition of `main'; src/lua.o:lua.c:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status

Any bit of help would be appreciated.

Panakotta00 commented 1 month ago

You are linking to all objects, which is not good as it also compiles the standalone Lua interpreter. The CLI tool. Link everything except the lua.o file, which appears to contain the CLI command.

The message multiple definition of 'main' hints that you try to build one binary with multiple main functions, which are the entry points for you executable. But you can't have one binary with multiple functions with the same signature (in this case the entry point main.

Perodactyl commented 1 month ago

Worked, thanks for the help.