linux下使用静态链接方式使用lua

环境是ubuntu9.04

首先去lua官方网站下载lua最新版

解压缩之后,从shell中进入目录,然后执行make

会给个提示,选择make的版本

因为是linux下,就打make linux

然后开始构建了,等下就好,进入src目录,里面有liblua.a

拷贝到项目需要的目录。

同时需要拷贝的是.h我建议把那头文件都拷贝到/usr/include下,这样以后用的时候方便,要不每次还得在gcc中加命令行

 在gcc中指定头文件参见:http://blog.chinaunix.net/u/28781/showart.php?id=401631

 然后写好代码就可以编译了。我的测试代码是:

ExpandedBlockStart.gif 代码
 1  void  load ( char   * filename,  int   * width,  int   * height) {
 2 
 3      lua_State  * =  lua_open();
 4 
 5      luaopen_base(L);
 6 
 7      luaopen_io(L);
 8 
 9      luaopen_string(L);
10 
11      luaopen_math(L);
12 
13   
14 
15       if  (luaL_loadfile(L, filename)  ||  lua_pcall(L,  0 0 0 ))
16 
17         error(L,  " cannot run configuration file: %s " ,
18 
19             lua_tostring(L,  - 1 ));
20 
21   
22 
23      lua_getglobal(L,  " width " );
24 
25      lua_getglobal(L,  " height " );
26 
27       if  ( ! lua_isnumber(L,  - 2 ))
28 
29         error(L,  " `width' should be a number\n " );
30 
31       if  ( ! lua_isnumber(L,  - 1 ))
32 
33         error(L,  " `height' should be a number\n " );
34 
35       * width  =  ( int )lua_tonumber(L,  - 2 );
36 
37       * height  =  ( int )lua_tonumber(L,  - 1 );
38 
39   
40 
41      lua_close(L);
42 
43  }
44 
45  int  main()
46  {
47       return   0 ;
48  }


 编译的命令行是:

gcc test.c -L$HOME/Code/luatest -llua -lm 

需要注意,gcc不用在静态库前加lib,得到的是liblua。。我刚开始编译的时候总提示找不到,后来在群里请教了一下大牛,解决了

还有-lm也是必须的,因为lua需要用到libm这个库

转载于:https://www.cnblogs.com/shiweifu/archive/2010/01/06/1640475.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值