如何用Lua构建C程序

 lantshirt 发布于 2023-02-12 11:33

test.c:

#include "lua.h"
#include "lauxlib.h"
#include "lualib.h"

int main(){

  lua_State *L = luaL_newState();  /* opens Lua */
  luaL_openlibs(L);   /* opens the standard libraries */

  luaL_dofile(L,"test.lua"); /* runs Lua scrip */

  lua_close(L);
  return 0;

}

建立:

gcc -o test test.c -I/usr/local/Cellar/lua/5.1.5/include

然后我得到了错误:

test.c:7:18: warning: implicit declaration of function 'luaL_newState' is
      invalid in C99 [-Wimplicit-function-declaration]
  lua_State *L = luaL_newState();  /* opens Lua */
                 ^
test.c:7:14: warning: incompatible integer to pointer conversion initializing
      'lua_State *' (aka 'struct lua_State *') with an expression of type 'int'
      [-Wint-conversion]
  lua_State *L = luaL_newState();  /* opens Lua */
             ^   ~~~~~~~~~~~~~~~
2 warnings generated.
Undefined symbols for architecture x86_64:
  "_luaL_loadfile", referenced from:
      _main in test-dxPwkn.o
  "_luaL_newState", referenced from:
      _main in test-dxPwkn.o
  "_luaL_openlibs", referenced from:
      _main in test-dxPwkn.o
  "_lua_close", referenced from:
      _main in test-dxPwkn.o
  "_lua_pcall", referenced from:
      _main in test-dxPwkn.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

我通过Homebrew安装了Lua:

ls /usr/local/Cellar/lua/5.1.5/include
lauxlib.h lua.h     lua.hpp   luaconf.h lualib.h

谁知道如何解决这个错误?谢谢.

撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有