无法从 Lua 中打开 C dll

我创建了一个非常简单的 C dll,现在我正在尝试使用 Lua 交互模式加载它

当我使用 require 时,我得到以下错误:

error loading module 'LuaExperiment' from file 'C:\Lua\5.2.4\LuaExperiment.dll' The specified procedure could not be found

当我使用 package.loadlib 时,我得到以下错误:

multiple Lua VMs detected

下面是我 Lua 安装文件夹的内容(LuaExperiment 是我的项目):

Contents of my Lua Folder

我使用以下步骤来创建上面的文件夹: 打开一个以管理员身份运行的 VS2015 开发人员命令提示符 输入以下命令:

> vcvars32
> cl /MD /O2 /c /DLUA_BUILD_AS_DLL *.c
> ren lua.obj lua.o
> ren luac.obj luac.o
> link /DLL /IMPLIB:lua5.2.4.lib /OUT:lua5.2.4.dll *.obj
> link /OUT:lua.exe lua.o lua5.2.4.lib
> lib /OUT:lua5.2.4-static.lib *.obj
> link /OUT:luac.exe luac.o lua5.2.4-static.lib

以下是我对项目属性进行的更改:

C:\Lua\5.2.4; 添加到 VC++ Directories->Include Directories

C\C++->Advanced->Compile As 更改为 Compile as C Code (/TC)

C:\Lua\5.2.4\*.lib; 添加到 Linker->Additional Dependencies

下面是 .h 和 .c 文件:

https://github.com/ImperfectVoid/C

点赞