Linux CentOS 编译LUA。。搞半天终于对了= =

2015/12/25 09:52
阅读数 3.3K

安装 wget http://www.lua.org/ftp/lua-5.2.1.tar.gz
tar -zvxf lua-5.2.1.tar.gz

make linux
错误:gcc -O2 -Wall -DLUA_COMPAT_ALL -DLUA_USE_LINUX -c -o lua.o lua.clua.c:67:31: error: readline/readline.h: No such file or directorylua.c:68:30: error: readline/history.h: No such file or directorylua.c: In function ‘pushline’:lua.c:271: warning: implicit declaration of function ‘readline’lua.c:271: warning: assignment makes pointer from integer without a castlua.c: In function ‘loadline’:lua.c:301: warning: implicit declaration of function ‘add_history’make[2]: *** [lua.o] Error 1make[2]: Leaving directory `/root/lua-5.2.0/src'make[1]: *** [linux] Error 2make[1]: Leaving directory `/root/lua-5.2.0/src'make: *** [linux] Error 2

解决:yum install -y readline-devel ncurses-devel

#include<stdio.h>
#include"lua.h"
#include"lauxlib.h"
#include"lualib.h"
#include "luaconf.h"
int main(){ lua_State *L; L = luaL_newstate(); luaL_openlibs(L); luaL_dofile(L,"test.lua"); lua_close(L);}

运行: gcc -o test tes.c -I/usr/local/lua/include/ -L/usr/local/lua/lib/ /usr/local/lua/lib/liblua.a -llua -lm -ldl 

错误1:没有引用liblua.a
/tmp/cckH9huG.o: In function `main':tes.c:(.text+0x12): undefined reference to `luaL_newstate'tes.c:(.text+0x20): undefined reference to `luaL_openlibs'tes.c:(.text+0x33): undefined reference to `luaL_loadfile'tes.c:(.text+0x5a): undefined reference to `lua_pcall'tes.c:(.text+0x65): undefined reference to `lua_close'collect2: ld returned 1 exit status

错误2:没有引用数学库 -llua -lm
/usr/local/lua/lib/liblua.a(lvm.o): In function `Arith':lvm.c:(.text+0xbdb): undefined reference to `pow'/usr/local/lua/lib/liblua.a(lvm.o): In function `luaV_execute':lvm.c:(.text+0x20b7): undefined reference to `pow'/usr/local/lua/lib/liblua.a(lcode.o): In function `codearith':lcode.c:(.text+0x11ec): undefined reference to `pow'/usr/local/lua/lib/liblua.a(lmathlib.o): In function `math_tan':lmathlib.c:(.text+0x1ee): undefined reference to `tan'/usr/local/lua/lib/liblua.a(lmathlib.o): In function `math_tanh':lmathlib.c:(.text+0x22e): undefined reference to `tanh'/usr/local/lua/lib/liblua.a(lmathlib.o): In function `math_sqrt':lmathlib.c:(.text+0x27d): undefined reference to `sqrt'/usr/local/lua/lib/liblua.a(lmathlib.o): In function `math_sin':lmathlib.c:(.text+0x2be): undefined reference to `sin'/usr/local/lua/lib/liblua.a(lmathlib.o): In function `math_sinh':lmathlib.c:(.text+0x2fe): undefined reference to `sinh'/usr/local/lua/lib/liblua.a(lmathlib.o): In function `math_pow':lmathlib.c:(.text+0x488): undefined reference to `pow'/usr/local/lua/lib/liblua.a(lmathlib.o): In function `math_log':lmathlib.c:(.text+0x52e): undefined reference to `log'/usr/local/lua/lib/liblua.a(lmathlib.o): In function `math_log10':lmathlib.c:(.text+0x56e): undefined reference to `log10'/usr/local/lua/lib/liblua.a(lmathlib.o): In function `math_fmod':lmathlib.c:(.text+0x678): undefined reference to `fmod'/usr/local/lua/lib/liblua.a(lmathlib.o): In function `math_exp':lmathlib.c:(.text+0x6be): undefined reference to `exp'/usr/local/lua/lib/liblua.a(lmathlib.o): In function `math_cos':lmathlib.c:(.text+0x6fe): undefined reference to `cos'/usr/local/lua/lib/liblua.a(lmathlib.o): In function `math_cosh':lmathlib.c:(.text+0x73e): undefined reference to `cosh'/usr/local/lua/lib/liblua.a(lmathlib.o): In function `math_atan':lmathlib.c:(.text+0x77e): undefined reference to `atan'/usr/local/lua/lib/liblua.a(lmathlib.o): In function `math_atan2':lmathlib.c:(.text+0x7d8): undefined reference to `atan2'/usr/local/lua/lib/liblua.a(lmathlib.o): In function `math_asin':lmathlib.c:(.text+0x81e): undefined reference to `asin'/usr/local/lua/lib/liblua.a(lmathlib.o): In function `math_acos':lmathlib.c:(.text+0x85e): undefined reference to `acos'/usr/local/lua/lib/liblua.a(loadlib.o): In function `ll_loadfunc':loadlib.c:(.text+0x947): undefined reference to `dlsym'loadlib.c:(.text+0x954): undefined reference to `dlerror'loadlib.c:(.text+0xa2c): undefined reference to `dlopen'loadlib.c:(.text+0xa41): undefined reference to `dlerror'/usr/local/lua/lib/liblua.a(loadlib.o): In function `gctm':loadlib.c:(.text+0x104e): undefined reference to `dlclose'collect2: ld returned 1 exit status

错误3:没有用-ldl 没找着这个是干什么用的,看起来像device

/usr/local/lua/lib/liblua.a(loadlib.o): In function `ll_loadfunc':loadlib.c:(.text+0x947): undefined reference to `dlsym'loadlib.c:(.text+0x954): undefined reference to `dlerror'loadlib.c:(.text+0xa2c): undefined reference to `dlopen'loadlib.c:(.text+0xa41): undefined reference to `dlerror'/usr/local/lua/lib/liblua.a(loadlib.o): In function `gctm':loadlib.c:(.text+0x104e): undefined reference to `dlclose'collect2: ld returned 1 exit status

展开阅读全文
打赏
0
0 收藏
分享
加载中
更多评论
打赏
0 评论
0 收藏
0
分享
在线直播报名
返回顶部
顶部