在Windows 7中为SWIG简单Lua示例创建共享库DLL时发生错误。

我使用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):对“lua_gettop”的未定义引用
example_wrap.o:example_wrap.c:(.text+0x2afe):对“lua_gettop”的未定义引用
example_wrap.o:example_wrap.c:(.text+0x2b2d):对“lua_pushfstring”的未定义引用
example_wrap.o:example_wrap.c:(.text+0x2b38):对“lua_error”的未定义引用
example_wrap.o:example_wrap.c:(.text+0x2b67):对“lua_pushnumber”的未定义引用
example_wrap.o:example_wrap.c:(.text+0x2ec0):对“lua_pushvalue”的未定义引用
example_wrap.o:example_wrap.c:(.text+0x2ee3):对“lua_pushstring”的未定义引用
example_wrap.o:example_wrap.c:(.text+0x2efe):对“lua_pushcclosure”的未定义引用
example_wrap.o:example_wrap.c:(.text+0x2f11):对“lua_rawset”的未定义引用
example_wrap.o:example_wrap.c:(.text+0x2f24):对“lua_pushstring”的未定义引用
example_wrap.o:example_wrap.c:(.text+0x2f3f):对“lua_pushcclosure”的未定义引用
example_wrap.o:example_wrap.c:(.text+0x2f52):对“lua_rawset”的未定义引用
collect2:ld返回1个退出状态

似乎我没有包含lua头文件? 因此,我也尝试了这些命令,但没有用

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

是否有建议?

点赞
用户2633423
用户2633423

尝试使用以下命令链接:

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-25 02:47:10