tags:

views:

123

answers:

1

We use Lua (www.lua.org) script to let users to customize our server software written in 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.

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).

It seems that some calling convention is wrong on 2010, like the application may be looking for the lua functions with a prefix '_'.

To access lua functions (written in C) from our project modules (C++) we use this:

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++).

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.

+1  A: 

The reported missing names are correct, this not a compile problem. You must be linking the wrong .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). Download it from here.

Hans Passant
I am compiling the lua library for myself from it source code (downloaded from www.lua.org). I did it as static and as DLL, with the same results (linking error). All my own libs are linking fine with VS 2010. Only linking LUA is not getting succeeded. Remember that everything works fine with VS 2008.
Jorg B Jorge
That was a very important detail, don't leave that out of your question. I cannot possibly guess how it was compiled wrong, use Dumpbin.exe on the .obj and .lib to verify that the symbols appear and have the __imp prefix. Something wrong with __declspec(dllexport) if you don't see that.
Hans Passant