1

我使用MinGW创建,我的lua版本是5.1.4 以下是我的步骤:

swig -lua  example.i
gcc -c example_wrap.c -I C:\Lua\5.1\include
gcc -c example.c -I C:\Lua\5.1\include
gcc -shared example_wrap.o example.o -o  example.dll

最后一步出现错误,这里是部分错误信息

example_wrap.o:example_wrap.c:(.text+0x2aef): undefined reference to `lua_gettop'
example_wrap.o:example_wrap.c:(.text+0x2afe): undefined reference to `lua_gettop'
example_wrap.o:example_wrap.c:(.text+0x2b2d): undefined reference to `lua_pushfstring'
example_wrap.o:example_wrap.c:(.text+0x2b38): undefined reference to `lua_error'
example_wrap.o:example_wrap.c:(.text+0x2b67): undefined reference to `lua_pushnumber'
example_wrap.o:example_wrap.c:(.text+0x2ec0): undefined reference to `lua_pushvalue'
example_wrap.o:example_wrap.c:(.text+0x2ee3): undefined reference to `lua_pushstring'
example_wrap.o:example_wrap.c:(.text+0x2efe): undefined reference to `lua_pushcclosure'
example_wrap.o:example_wrap.c:(.text+0x2f11): undefined reference to `lua_rawset'
example_wrap.o:example_wrap.c:(.text+0x2f24): undefined reference to `lua_pushstring'
example_wrap.o:example_wrap.c:(.text+0x2f3f): undefined reference to `lua_pushcclosure'
example_wrap.o:example_wrap.c:(.text+0x2f52): undefined reference to `lua_rawset'
collect2: ld returned 1 exit status

看来我没有包含lua标头?所以我也尝试了这些命令但没有用

gcc -shared example_wrap.o example.o  -I C:\Lua\5.1\include -o  example.dll

所以有什么建议吗?

4

1 回答 1

2

尝试使用此命令链接:

gcc -LC:\Lua\5.1\bin -shared example_wrap.o example.o -llua51 -o example.dll

-LC:\Lua\5.1\bin部分中的路径应指向您拥有的目录lua51.dll(我假设bin,就像在我的系统中一样,但更改它以适合您的安装)。

于 2013-08-25T02:47:10.270 回答