使用Visual Studio为Lua创建C模块DLL

我正在尝试创建一个C DLL来扩展我在C ++应用程序中使用的Lua脚本。

我的DLL代码位于"mylib.h"中:

#include <iostream>
#include "lua.hpp"
extern "C"
{
static int l_hello(lua_State *L) {
    std::cout << "sup lol?" << std::endl;
    return 0;
}

static const struct luaL_Reg mylib[] = {
    { "l_hello", l_hello },
    { NULL,NULL }
};

__declspec(dllexport) int luaopen_mylib(lua_State *L)
{
    std::cout << "loading my lib" << std::endl;
    luaL_newlib(L, mylib);
    return 1;
}
}

我构建了上述代码并将DLL“mylib.dll”放置在应用程序的调试文件夹中。当我运行应用程序时,该程序出现错误:

local mylib = require "mylib"

并显示“error loading module 'mylib' from file 'C:\Users\Username\Documents\Visual Studio 2015\Projects\Project1Tests\Debug\mylib.dll': 指定的模块无法找到”。

我该如何解决这个问题?

点赞