You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

GameMaker加载集成Lua的DLL时出现Error 126问题求助

问题描述

我要开发一款游戏的模组,需要编写一个集成Lua语言的DLL库。连接Lua库时一切正常,但一旦调用Lua函数,GameMaker 2.0编译器就抛出Error 126错误。已确认DLL和Lua库均为64位编译版本,仍无法定位问题。

DLL代码

#include "pch.h"
#include <iostream>

#define GMDLL extern "C" __declspec(dllexport)

extern "C"
{
     #include "lua/include/lua.h"
     #include "lua/include/lualib.h" 
     #include "lua/include/lauxlib.h"
 }

     #pragma comment(lib, "lua/liblua54.a")


GMDLL double DLLTest()
{
    lua_State* L = luaL_newstate();

    lua_close(L);

    std::cout << "success" << std::endl;
    return 0;
}

错误信息

LoadLibraryW("PATH_TO_DLL") for function "DLLTest" failed with error code 126 ("The specified module could not be found.")
LoadLibraryW("PATH_TO_DLL") for function "?YYExtensionInitialise@@YAXPEBUYYRunnerInterface@@_K@Z" failed with error code 126 ("The specified module could not be found.")
LoadLibraryW("PATH_TO_DLL") for function "?YYExtensionInitialise@@YA_NPEBUYYRunnerInterface@@_K@Z" failed with error code 126 ("The specified module could not be found.")
LoadLibraryW("PATH_TO_DLL") for function "?YYExtensionInitialise@@YANPEBUYYRunnerInterface@@_K@Z" failed with error code 126 ("The specified module could not be found.")
排查与解决方法
  • 检查Lua库链接方式:当前使用的是静态库liblua54.a,需确认Lua是纯静态编译版本。若Lua编译为动态库模式,静态链接会导致依赖缺失,此时应改用动态链接,并将Lua的DLL文件放到GameMaker运行目录或系统PATH可访问的路径中。
  • 排查依赖库缺失:Error 126本质是DLL依赖的模块找不到,可使用dumpbin /dependents 你的DLL文件.dll工具查看所有依赖项,确保VC++运行时库、Lua相关库等所有依赖都存在于GameMaker能读取的路径(如游戏exe目录、DLL所在目录)。
  • 实现GameMaker扩展接口:错误中提到的YYExtensionInitialise系列函数是GameMaker对扩展DLL的强制要求,必须在代码中添加对应初始化函数,示例:
    GMDLL void YYExtensionInitialise(const YYRunnerInterface* runner, uint64_t reserved) {
        // 可在此保存runner指针,用于后续调用GameMaker接口
    }
    
    未实现这些函数会导致GameMaker加载DLL失败。
  • 匹配编译Runtime设置:确保DLL编译时的Runtime库选项与GameMaker一致(如均使用MD/MDd动态CRT,避免使用MT/MTd静态CRT),CRT版本不兼容会直接导致加载失败。
  • 验证路径正确性:检查DLL文件路径无特殊字符,GameMaker能准确定位到该文件;同时确认编译时Lua头文件和库的引用路径正确,未混用不同版本的Lua文件。

内容的提问来源于stack exchange,提问作者Pyr0Guy

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.12 18:55:56