使用 LuaBinaries 和 LuaBridge 时如何解决丢失的 Lua DLL?

How to resolve missing Lua DLL when using LuaBinaries and LuaBridge?

我正在尝试将 Lua 嵌入到 C++ 中(并学习 Lua),从 Elias Daler 的训练轮方法 here. I'm using MSVC 14.0, LuaBinaries 5.3.2 - Release 1 (specifically, lua-5.3.2_Win32_dllw4_lib.zip here) 和 LuaBridge 开始2.0.

我添加了以下附加包含目录:

C:\lua-5.3.2_Win32_dllw4_lib\include;C:\LuaBridge

以及以下附加依赖项:

C:\lua-5.3.2_Win32_dllw4_lib\liblua53.a

我正在使用以下来源(尽可能精简):

#include "stdafx.h"
#include <LuaBridge.h>

int main() {
    luabridge::lua_State* L = luabridge::luaL_newstate();
}

该源编译和链接正常,但应用程序本身导致标准缺失 DLL 系统错误:

The program can't start because lua53.dll is missing from your computer. Try reinstalling the program to fix this problem.

lua53.dll 在 C:\lua-5.3.2_Win32_dllw4_lib\ — 我错过了什么?

根据 official Microsoft documentation,Windows 在以下目录中搜索 DLL:

  1. The directory where the executable module for the current process is located.

  2. The current directory.

  3. The Windows system directory. The GetSystemDirectory function retrieves the path of this directory.

  4. The Windows directory. The GetWindowsDirectory function retrieves the path of this directory.

  5. The directories listed in the PATH environment variable.

因此,解决问题的一种方法是将 C:\lua-5.3.2_Win32_dllw4_lib 添加到当前用户的 PATH

与其他选项相比,这具有不需要管理员权限和不需要 lua53.dll 位于当前目录或与您的可执行文件相同的目录的优点。