简体   繁体   English

将Lua与Visual Studio 2010链接

[英]Linking Lua with Visual Studio 2010

We use Lua (www.lua.org) script to let users to customize our server software written in C++. 我们使用Lua(www.lua.org)脚本让用户自定义我们用C ++编写的服务器软件。

At the moment we are porting the 32 bits Windows version of our project to Visual Studio 2010. Once everything works fine with VS 2008, we thought that we would have no problem on upgrade process. 目前我们正在将32位Windows版本的项目移植到Visual Studio 2010.一旦VS 2008的一切正常,我们认为升级过程没问题。

Unfortunately whenever we tried to link the lualib (as dll) to our project in VS 2010, the lua functions could not be found by the linker (the error messages are displayed below). 不幸的是,每当我们尝试将lualib(作为dll)链接到VS 2010中的项目时,链接器都找不到lua函数(错误消息显示在下面)。

It seems that some calling convention is wrong on 2010, like the application may be looking for the lua functions with a prefix '_'. 在2010年,似乎某些调用约定是错误的,就像应用程序可能正在寻找带有前缀“_”的lua函数一样。

To access lua functions (written in C) from our project modules (C++) we use this: 要从我们的项目模块(C ++)访问lua函数(用C编写),我们使用:

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

The same project compiles and links with lualib successfully on VS 2008 and Linux (g++). 同一个项目在VS 2008和Linux(g ++)上成功编译并链接到lualib。

Could anybody help me with this ? 有人可以帮帮我吗?

1>dscscript.obj : error LNK2019: unresolved external symbol __imp__luaL_openlibs referenced in function "public: int __thiscall DsCScriptEngine::Init(void)" (?Init@DsCScriptEngine@@QAEHXZ)

1>dscscript.obj : error LNK2019: unresolved external symbol __imp__luaL_newstate referenced in function "public: int __thiscall DsCScriptEngine::Init(void)" (?Init@DsCScriptEngine@@QAEHXZ)

1>dscscript.obj : error LNK2019: unresolved external symbol __imp__lua_close referenced in function "public: void __thiscall DsCScriptEngine::Shutdown(void)" (?Shutdown@DsCScriptEngine@@QAEXXZ)

1>dscscript.obj : error LNK2019: unresolved external symbol __imp__lua_pcall referenced in function "public: long __thiscall DsCScriptEngine::Execute(char const *)" (?Execute@DsCScriptEngine@@QAEJPBD@Z)

etc. 等等

The reported missing names are correct, this not a compile problem. 报告的缺失名称是正确的,这不是编译问题。 You must be linking the wrong .lib. 你必须链接错误的.lib。 The name you use sounds wrong, it isn't "lualib", the current version of the import library is named lua5.1.lib (or lua51.lib, not sure what the difference is). 您使用的名称听起来不对,它不是“lualib”,导入库的当前版本名为lua5.1.lib(或lua51.lib,不确定区别是什么)。 Download it from here . 从这里下载。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM