编译链接器文件,以将 C 代码嵌入到 Lua 5.2.1 中。
2015-3-4 7:34:15
收藏:0
阅读:74
评论:0
如何在 Visual Studio 2010 中为连接器编译文件。
以下是我在 Visual Studio 2010 中使用 Lua 5.2.1 源代码所遵循的步骤:
- 使用以下命令 cl /MD /O2 /c /DLUA_BUILD_AS_DLL *.c 进行编译
- 重命名 "lua.obj" 和 "luac.obj" 文件以 ".o" 做为扩展名,以避免它们被选择
- 使用以下命令进行链接:link /DLL /IMPLIB:lua5.2.lib /OUT:lua5.2.dll *.obj
- 使用以下命令进行链接:link /OUT:lua.exe lua.o lua5.2.lib
- 使用以下命令进行链接:lib /OUT:lua5.2-static.lib *.obj
- 使用以下命令进行链接:link /OUT:luac.exe luac.o lua5.2-static.lib
从以上所有步骤中,我选择其中的 lua5.2.lib 并将其添加到链接器中,如下所示:

但是,当我使用 Dev-C++ 编译以下 C 代码时,并不会出现任何错误。但是,当我使用 require 命令从 Lua 中调用它时,它说它找不到。
#include<windows.h>
#include<math.h>
#include "lauxlib.h"
#include "lua.h"
#define LUA_LIB int __declspec(dllexport)
static int IdentityMatrix(lua_State *L)
{
int in = lua_gettop(L);
if (in!=1)
{
lua_pushstring(L,"Maximum 1 argument");
lua_error(L);
}
lua_Number n = lua_tonumber(L,1);
lua_newtable(L); /* tabOUT n */
int i,j;
for (i=1;i<=n;i++)
{
lua_newtable(L); /* row(i) tabOUT n */
lua_pushnumber(L,i); /* i row(i) tabOUT n */
for (j=1;j<=n;j++)
{
lua_pushnumber(L,j); /* j i row(i) tabOUT n */
if (j==i)
{
lua_pushnumber(L,1);
}
else /* 0/1 j i row(i) tabOUT n */
{
lua_pushnumber(L,0);
}
/* Put 0/1 inside row(i) at j position */
lua_settable(L,-4); /* i row(i) tabOUT n */
}
lua_insert(L,-2); /* row(i) i tabOUT n */
lua_settable(L,2); /* tabOUT n */
}
return 1;
}
static const struct luaL_Reg LuaMath [] = {{"IdentityMatrix", IdentityMatrix},
{ NULL, NULL}};
LUA_LIB luaopen_LuaMath(lua_State *L)
{
luaL_newlib(L,LuaMath);
return 1;
}
当我运行以下简单 Lua 代码时:
require("LuaMath")
A=LuaMath.IdentityMatrix(4)
错误消息写道
error loading module 'LuaMath' from file './LuaMath.dll': impossible to find the specified module'.
有什么帮助吗?
点赞
评论区的留言会收到邮件通知哦~
推荐文章
- 如何将两个不同的lua文件合成一个 东西有点长 大佬请耐心看完 我是小白研究几天了都没搞定
- 如何在roblox studio中1:1导入真实世界的地形?
- 求解,lua_resume的第二次调用继续执行协程问题。
- 【上海普陀区】内向猫网络招募【Skynet游戏框架Lua后端程序员】
- SF爱好求教:如何用lua实现游戏内调用数据库函数实现账号密码注册?
- Lua实现网站后台开发
- LUA错误显式返回,社区常见的规约是怎么样的
- lua5.3下载库失败
- 请问如何实现文本框内容和某个网页搜索框内容连接,并把网页输出来的结果反馈到另外一个文本框上
- lua lanes多线程使用
- 一个kv数据库
- openresty 有没有比较轻量的 docker 镜像
- 想问一下,有大佬用过luacurl吗
- 在Lua执行过程中使用Load函数出现问题
- 为什么 neovim 里没有显示一些特殊字符?
- Lua比较两个表的值(不考虑键的顺序)
- 有个lua简单的项目,外包,有意者加微信 liuheng600456详谈,最好在成都
- 如何在 Visual Studio 2022 中运行 Lua 代码?
- addEventListener 返回 nil Lua
- Lua中获取用户配置主目录的跨平台方法