Linux CentOS 编译LUA。。搞半天终于对了= =
lua吧
全部回复
仅看楼主
level 6
不屑宠儿 楼主
安装 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
2013年03月01日 08点03分 1
level 2
It is fu!!cking great!!帮了我大忙了!!!!十分感谢感谢!!!![花心]
2014年06月14日 16点06分 3
[勉强]
2014年06月15日 06点06分
回复 慕婧 :[乖]
2014年06月20日 03点06分
也帮了我的fu!!cking的大忙
2015年06月11日 13点06分
level 1
[大拇指]
2015年08月11日 08点08分 4
level 11
干的好!![真棒]
2015年08月11日 14点08分 5
level 12
[乖]最近好多编译源码的
2015年08月12日 04点08分 6
好几年的东西了,,被你们挖坟出来斑竹居然也没删哈哈~
2015年08月15日 11点08分
level 6
不屑宠儿 楼主
看那么多人用到这个,,顺便补充一个C/C++嵌入调用LUA编译错误的情况,大家收藏起来哟~这可不好找到~
1. 编译lua的时候,记得在Makefile里加上-fPIC !!! 注意是编译lua的Makefile,不是自己的!
2. lua函数原型: typedef int (*lua_CFunction) (lua_State *L);
3. c++的luaopen函数前面要加 extern "C" !!
2015年08月15日 11点08分 7
lua吧人少,挖挖坟也好,你看不就挖出了好动西了嘛
2015年08月24日 13点08分
回复
Э����־_Tox
:[冷]
2015年08月30日 09点08分
回复
ħ�g������
:挖的一手好坟嘛,哈哈
2015年08月30日 09点08分
回复
Э����־_Tox
:好久没动静了。。原来您还活着。。[滑稽]
2015年08月30日 10点08分
level 1
谢谢一护同学
2018年05月27日 07点05分 8
1