python - 在windows上编译疯狂的python

标签 python c lua

我正在尝试使用 minigw 在 Windows 上编译疯狂的 python。命令如下:

 gcc.exe -shared -DLUA_BUILD_AS_DLL src\luainpython.c src\pythoninlua.c liblua.a
 libpython27.a -IC:\Python27\include -IC:\LUA\include 

这给了我未定义的引用错误。但我找不到任何 lua api 更改引用,我应该用什么来替换它们。

src\luainpython.c:350:14: warning: 'LuaObject_Type' redeclared without dllimport
attribute after being referenced with dll linkage [enabled by default]
C:\Users\Wiz\AppData\Local\Temp\cccm0nAN.o:luainpython.c:(.text+0x7a): undefined
     reference to `lua_strlen'
C:\Users\Wiz\AppData\Local\Temp\cccm0nAN.o:luainpython.c:(.text+0x557): undefine
    d reference to `_imp__LuaObject_Type'
C:\Users\Wiz\AppData\Local\Temp\cccm0nAN.o:luainpython.c:(.text+0xc3a): undefine
    d reference to `luaL_getn'
C:\Users\Wiz\AppData\Local\Temp\cccm0nAN.o:luainpython.c:(.text+0x1036): undefin
    ed reference to `luaopen_loadlib'
c:/mingw32/bin/../lib/gcc/i686-w64-mingw32/4.7.1/../../../../i686-w64-mingw32/bi
    n/ld.exe: C:\Users\Wiz\AppData\Local\Temp\cccm0nAN.o: bad reloc address 0x0 in s
    ection `.data'
collect2.exe: error: ld returned 1 exit status

最佳答案

原始的 Lunatic-Python 代码库有许多已知问题 - 您上面遇到的构建问题就是其中之一。不幸的是,原作者似乎不再维护这个项目了——如果最后修改日期here是否有任何指示。

如果您仍在尝试让它工作,我强烈建议您使用最新的前叉之一。特别是Lunantic-Python fork at github包含了我的许多修复改进。

回到你的问题,许多 undefined reference 是由于 header 中不正确的前向声明或由于定义的宏导致前向声明不正确造成的。例如,原始的luainpython.h包含:

PyAPI_DATA(PyTypeObject) LuaObject_Type;

在Windows中,预处理后它扩展为:

extern __declspec(dllimport) PyTypeObject LuaObject_Type;

换句话说,链接器将尝试从导入库中查找 LuaObject_Type 的定义。这当然是错误的,因为这个新类型是由 lunatic 在 luainpython.c 中创建和实现的。正确的原型(prototype)应该是 extern PyTypeObject LuaObject_Type;

另请注意,luaopen_loadlib 在 Lua5.1 中已弃用,这解释了您获得的其他 undefined reference 。事实上,lunatic-python 对以下内容的使用均已被弃用:

luaopen_base(L);
luaopen_table(L);
luaopen_io(L);
luaopen_string(L);
luaopen_debug(L);
luaopen_loadlib(L);

并且应该替换为:

luaL_openlibs(L);

关于python - 在windows上编译疯狂的python,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12225782/

相关文章:

python - 如何更改列表的顺序,同时保留对原始 Python 的引用

python - 使用 Python re 转换注释//with/*

c - 删除数组中相同的项

Lua 自定义数字串联

lua - 如何解决这个解包问题?

string - 如何重载Lua字符串下标运算符?

python - Django 2.1.7 : Populate Child field with Selected Parent Attributes in Product Model

python - 使用 Path 上的模块运行 py.test 时出现模块导入错误

c++ - emacs C/C++ 缩进 : different for pre and post comments//or: how can I make certain comments like//^ be indented extra?

c++ - 在 CPP 类中声明一个 C 函数作为友元