我试图将(静态的)luajitembedded到c ++应用程序中失败。 我一直按照luajit网站上的步骤行事,并没有find相关的信息,并尝试了所有我能想到的事情。
看起来好像我正在运行的问题是g ++没有正确链接,或者luajit不能正确构build。
这就是我想要编译的东西:
#include <lua.h> #include <lauxlib.h> #include <lualib.h> int main(void) { lua_State *L = luaL_newstate(); luaL_openlibs(L); lua_close(L); return 0; }
而我得到的错误是一个undefined reference
错误,就好像我没有连接luajit。
main.cpp:7: undefined reference to `luaL_newstate()' main.cpp:9: undefined reference to `luaL_openlibs(lua_State*)' main.cpp:10: undefined reference to `lua_close(lua_State*)'
我试图用eclipse cdt(mingw)编译它后,设置链接选项如下:
Library Paths: D:/includes/LuaJIT-2.0.1/src Includes (GNU G++): D:/includes/LuaJIT-2.0.1/src Libraries: luajit
和eclipse cdt似乎试图编译它如下:
g++ -ID:/includes/LuaJIT-2.0.1/src -O0 -g3 -pedantic-errors -Wall -Wextra -Werror -Wconversion -c -fmessage-length=0 -Weffc++ -std=c++11 -o "source\\main.o" "..\\source\\main.cpp" g++ -LD:/includes/LuaJIT-2.0.1/src -o test.exe "source\\main.o" -lluajit
我已经从他们的下载页面下载了LuaJIT-2.0.1 zip (最新版本),并按照以下安装指南进行操作:
LuaJIT-2.0.1/src/
make BUILDMODE=static
并得到了一个很好的OK Successfully built LuaJIT
消息 除此之外,没有很多关于embeddedluajit的信息,甚至没有在安装指南 。
但是,为luaL_newstate
src
文件夹会在luaL_newstate
返回一个匹配libluajit.a
。
grep -r "luaL_newstate" . ./host/genminilua.lua: lua_State *L = luaL_newstate(); ./host/minilua.c:static lua_State*luaL_newstate(void){ ./host/minilua.c:lua_State*L=luaL_newstate(); ./lauxlib.h:LUALIB_API lua_State *(luaL_newstate) (void); Binary file ./libluajit.a matches ./lib_aux.c:LUALIB_API lua_State *luaL_newstate(void) ./lib_aux.c:LUALIB_API lua_State *luaL_newstate(void) ./lib_aux.c: fputs("Must use luaL_newstate() for 64 bit target\n", stderr); Binary file ./lib_aux.o matches ./lua.h:#define lua_open() luaL_newstate() Binary file ./luajit.exe matches Binary file ./luajit.o matches
我在用着:
g++ (rev, Built by MinGW-builds project) 4.8.0 20130314 (experimental)
GNU Make 3.82.90 Built for i686-pc-msys
将你的include
指令包装成extern "C" { ... }
您应该在C ++代码中使用#include "lua.hpp"
, 而不是 lua.h
这在C API文档的顶部提到。