【求助】lua加载用C编写的dll失败
lua吧
全部回复
仅看楼主
level 1
各位前辈好,最近开始学习Lua,尝试用C写一个DLL,然后Lua脚本加载它,但是失败了,过程如下:
首先是C的代码
然后,编译链接生成DLL文件
然后,在Lua脚本里代码如下
local mylib = require("mylib")
但是问题来了
lua: error loading module 'mylib' from file '.\mylib.dll': %1 si not a valid Win32 application.
本人之前没有接触过Lua,虽然用C和C++,但未曾涉及到编译生成DLL文件,所以并不知道是哪一个环节出了问题,望高手解答,谢谢!
2017年01月12日 00点01分 1
level 1
DLL函数你要加导出符号,先搜索dllexport看看
2017年01月12日 02点01分 2
level 1
另外若是c++编译器请extern "C"避免名字粉碎
2017年01月12日 02点01分 3
你好,我之前的这个问题解决了,原因是32-BIT的DLL和64-BIT的程序混用的原因。现在出了个新问题,lua: error loading module 'array' from file '.\array.dll': The specified procedure could not be found. 但是我代码里确有写luaopen_mylib()函数,请问你知道原因吗?谢谢
2017年01月13日 00点01分
@莫斯特亨特 如果改了,贴新代码,没改,原因还是之前说的。你先找个dll符号查看工具看看有没有导出
2017年01月13日 02点01分
level 11
你写的是local mylib = require("mylib")还是local mylib = require("array")……
2017年01月13日 02点01分 5
level 11
[喷]
2017年01月13日 02点01分 6
level 1
好吧,我的问题已经解决了,确实需要dllexport和extern “C”关键字,而且lua interpreter和C module也都需要动态链接lua库。谢谢给位的解答!
2017年01月13日 20点01分 7
1