0

So I migrated servers on a project of mine and now it won't compile. I believe I've installed all the necessary libraries, but I keep getting undefined reference errors.

wsayin@sapper:~/mud/lua$ make linux
cd src && make linux
make[1]: Entering directory `/home/wsayin/mud/lua/src'
make all SYSCFLAGS="-DLUA_USE_LINUX" SYSLIBS="-Wl,-E -ldl -lreadline"
make[2]: Entering directory `/home/wsayin/mud/lua/src'
make[2]: Nothing to be done for `all'.
make[2]: Leaving directory `/home/wsayin/mud/lua/src'
make[1]: Leaving directory `/home/wsayin/mud/lua/src'
wsayin@sapper:~/mud/lua$ sudo make install
cd src && mkdir -p /usr/local/bin /usr/local/include /usr/local/lib /usr/local/man/man1 /usr/local/share/lua/5.2 /usr/local/lib/lua/5.2
cd src && install -p -m 0755 lua luac /usr/local/bin
cd src && install -p -m 0644 lua.h luaconf.h lualib.h lauxlib.h lua.hpp /usr/local/include
cd src && install -p -m 0644 liblua.a /usr/local/lib
cd doc && install -p -m 0644 lua.1 luac.1 /usr/local/man/man1

That's what I got from doing make linux && sudo make install, as per the Lua directions. I can see that liblua.a is located in /usr/local/lib and all the .h files are located in /usr/local/include

My Makefile is as follows:

CC      = gcc

BIN_NAME = dark.test

LUA_LIB_DIR = /usr/local/lib
LUA_INCLUDE = /usr/local/include

MYSQL_LIB_DIR = /usr/lib/mysql
MYSQL_INCLUDE = /usr/include/mysql

LIB_DIRS =  -L$(LUA_LIB_DIR) -L$(MYSQL_LIB_DIR)
INCLUDES = -I$(SHARED_STR_INCLUDE) -I$(LUA_INCLUDE) -I$(MYSQL_INCLUDE)

C_FLAGS = -Wall -Wextra -Wno-long-long -ggdb -pedantic -std=c99 $(INCLUDES)  -fstack-protector
L_FLAGS = -lz -lpthread -lcrypt -llua -lm $(LIB_DIRS) -lmysqlclient

O_FILES = socket.o io.o strings.o utils.o interpret.o help.o  \
          action_safe.o mccp.o save.o event.o handler_events.o\
          list.o stack.o handler_mysql.o handler_connections.o \
          handler_lua.o accounts.o world.o comm.o rand.o

all: $(O_FILES)
        rm -f $(BIN_NAME)

        $(CC) -o $(BIN_NAME) $(O_FILES) $(L_FLAGS) $(C_FLAGS)

.c.o: all
        @echo [`date +%T`] Compiling $< ...
        @$(CC) -c $(C_FLAGS) $<

clean:
        @echo Cleaning code $< ...
        @rm -f *.o
        @rm -f $(BIN_NAME)
        @rm -f *.*~

Yet when I compile, I get

wsayin@sapper:~/mud/src$ make
rm -f dark.test
gcc -o dark.test socket.o io.o strings.o utils.o interpret.o help.o action_safe.o mccp.o save.o event.o handler_events.o list.o stack.o handler_mysql.o handler_connections.o handler_lua.o accounts.o world.o comm.o rand.o -lz -lpthread -lcrypt -llua -lm -L/usr/local/lib -L/usr/lib/mysql -lmysqlclient -Wall -Wextra -Wno-long-long -ggdb -pedantic -std=c99 -I -I/usr/local/include -I/usr/include/mysql  -fstack-protector
save.o: In function `load_player':
/home/wsayin/mud/src/save.c:36: undefined reference to `lua_open'
handler_lua.o: In function `init_lua':
/home/wsayin/mud/src/handler_lua.c:27: undefined reference to `lua_open'
handler_lua.o: In function `load_mud_settings':
/home/wsayin/mud/src/handler_lua.c:44: undefined reference to `lua_open'
world.o: In function `load_world':
/home/wsayin/mud/src/world.c:51: undefined reference to `lua_open'
world.o: In function `load_area_objects':
/home/wsayin/mud/src/world.c:180: undefined reference to `luaL_getn'
world.o: In function `load_area_mobiles':
/home/wsayin/mud/src/world.c:211: undefined reference to `luaL_getn'
world.o: In function `load_area_rooms':
/home/wsayin/mud/src/world.c:242: undefined reference to `luaL_getn'
world.o: In function `load_room_resets':
/home/wsayin/mud/src/world.c:267: undefined reference to `luaL_getn'
world.o: In function `load_room':
/home/wsayin/mud/src/world.c:314: undefined reference to `luaL_getn'
collect2: ld returned 1 exit status
make: *** [all] Error 1

I'm at a complete loss for what to do, I feel like everything is where it should be yet its not finding the right libraries. Thoughts?

Will
  • 33
  • 1
  • 8
  • 1
    Have you tried specifying the directories that contain the libraries to link against **before** these? I mean, do `-L/foo/bar` and then `-llua`. –  Apr 08 '14 at 17:35
  • Possible duplicate of http://stackoverflow.com/questions/8552560/embedding-lua-in-c ... also see http://lua-users.org/lists/lua-l/2006-07/msg00329.html ... or Google lua_open undefined, there are lots of hits. – esorton Apr 08 '14 at 22:50
  • You got it, esorton, well, the comments in one of the links you posted did-- my previous server was using Lua 5.1, and some of the functions I was using had become deprecated, which was what was causing the issues. – Will Apr 09 '14 at 04:12

0 Answers0