從官網上下載5.3.2的源碼后,make linux進行編譯,提示報錯:
gcc -std=gnu99 -o lua lua.o liblua.a -lm -Wl,-E -ldl -lreadline /usr/local/lib/libreadline.so:對‘tputs’未定義的引用 /usr/local/lib/libreadline.so:對‘tgoto’未定義的引用 /usr/local/lib/libreadline.so:對‘tgetflag’未定義的引用 /usr/local/lib/libreadline.so:對‘UP’未定義的引用 /usr/local/lib/libreadline.so:對‘tgetent’未定義的引用 /usr/local/lib/libreadline.so:對‘tgetnum’未定義的引用 /usr/local/lib/libreadline.so:對‘PC’未定義的引用 /usr/local/lib/libreadline.so:對‘tgetstr’未定義的引用 /usr/local/lib/libreadline.so:對‘BC’未定義的引用 collect2: error: ld returned 1 exit status Makefile:63: recipe for target 'lua' failed make[2]: *** [lua] Error 1 make[2]: Leaving directory '/home/abuu/project/lua-5.3.2/src' Makefile:110: recipe for target 'linux' failed make[1]: *** [linux] Error 2 make[1]: Leaving directory '/home/abuu/project/lua-5.3.2/src' Makefile:55: recipe for target 'linux' failed make: *** [linux] Error 2
報錯原因是無法從libreadline.so庫中定位tputs、tgoto等函數位置,那這些函數可能是由其他共享庫所引入。
上網查詢一下這些函數,發現這些函數來源於ncurses,於是從官網上下載ncurses源碼進行編譯。
安裝完ncurses后再次"make linux"試了試,依然報錯,於是檢查、添加依賴,在src/Makefile中修改如下:
linux: $(MAKE) $(ALL) SYSCFLAGS="-DLUA_USE_LINUX" SYSLIBS="-Wl,-E -ldl -lreadline -lncurses"
保存后再次編譯,通過。