VS2012 + Lua

So I've been following this tutorial http://www.youtube.com/watch?v=X5D_h2X8LCk , however Im getting errors about thaat my lib is not linked, however, IT IS, I have included both include and lib folders in project properties, lua5.2.lib is also included in the input of linker, not only in the code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <lua.hpp>
#include <Windows.h>

#pragma comment(lib, "lua5.2.lib")

int main(int argc, char** argv) {
  lua_State *L = luaL_newstate();
  luaL_openlibs(L);
 
  if (luaL_dofile(L, "test.lua")) {
    const char* err = lua_tostring(L, -1);
    printf(err);
  }
 
  lua_close(L);
 
  getchar();
  return 0;
}


1>Source.obj : error LNK2019: unresolved external symbol _lua_close referenced in function _main
1>Source.obj : error LNK2019: unresolved external symbol _lua_tolstring referenced in function _main
1>Source.obj : error LNK2019: unresolved external symbol _lua_pcallk referenced in function _main
1>Source.obj : error LNK2019: unresolved external symbol _luaL_openlibs referenced in function _main
1>Source.obj : error LNK2019: unresolved external symbol _luaL_loadfilex referenced in function _main
1>Source.obj : error LNK2019: unresolved external symbol _luaL_newstate referenced in function _main


+ lua in cmd works just fine
Last edited on
bump
1. Have you turned on verbose logging for linking and checked to see if anything suspicious is going on?

Projects Properties > Linker > General

Show Progress = Display all progress messages (/VERBOSE)

2. You could dump the library and see if there's something wrong there. From a Visual Studio command prompt:

C:\Program Files\Lua\5.2\lib>link /dump /linkermember:1 lua5.2.lib > lua_exps.txt

Where the outputs being piped it into a text file for easier readability; if the lib file is ok you will see _luaL_newstate, _luaL_openlibs, etc there.

Andy
Last edited on
2. something, like this?

Microsoft (R) COFF/PE Dumper Version 11.00.50727.1
Copyright (C) Microsoft Corporation. All rights reserved.


Dump of file lua5.2.lib

File Type: LIBRARY

Archive member name at 8: /
526194FB time/date Fri Oct 18 22:07:23 2013
uid
gid
0 mode
1862 size
correct header end

297 public symbols

314E __IMPORT_DESCRIPTOR_lua5.2
3374 __NULL_IMPORT_DESCRIPTOR
34AA lua5.2_NULL_THUNK_DATA
4A06 __imp_lua_atpanic
4A06 lua_atpanic
6D38 __imp_lua_version
6D38 lua_version
4938 __imp_lua_absindex
4938 lua_absindex
535C __imp_lua_gettop
535C lua_gettop
6638 __imp_lua_settop
6638 lua_settop
5E14 __imp_lua_pushvalue
5E14 lua_pushvalue
6224 __imp_lua_remove
6224 lua_remove
5498 __imp_lua_insert
5498 lua_insert


1. the only suspicious thing I noticed was lua5.2 listed in the "unused libraries" list, but program can find it, since when I changed the name of the file I got error about lua5.2 not being able to find
Well, the symbols don't look right in your dump -- they're missing the leading underscores.

I've just run through the exercise using Visual Studio 2012 (with no problems) and the dump I get begins:

Microsoft (R) COFF/PE Dumper Version 11.00.60610.1
Copyright (C) Microsoft Corporation.  All rights reserved.


Dump of file lua5.2.lib

File Type: LIBRARY

Archive member name at 8: /               
5263DD5D time/date Sun Oct 20 14:40:45 2013
         uid
         gid
       0 mode
    1988 size
correct header end

    297 public symbols

     339A __IMPORT_DESCRIPTOR_lua5.2
     35C0 __NULL_IMPORT_DESCRIPTOR
     36F6 lua5.2_NULL_THUNK_DATA
     4C72 __imp__lua_atpanic
     4C72 _lua_atpanic
     7004 __imp__lua_version
     7004 _lua_version
     4BA2 __imp__lua_absindex
     4BA2 _lua_absindex
     55E0 __imp__lua_gettop
     55E0 _lua_gettop
     68F2 __imp__lua_settop
     68F2 _lua_settop
     60B8 __imp__lua_pushvalue
     60B8 _lua_pushvalue
     64D2 __imp__lua_remove
     64D2 _lua_remove
     5722 __imp__lua_insert
     5722 _lua_insert


You can see my symbols have the leading underscore.

I followed the instructions pretty closely (I just didn't bother to type the switches in capitals when the linker doesn't care whether you use /OUT or /out, etc.)

I can't think of an obvious reason why the symbols are missing the underscore.

Andy
Last edited on
Just had a thought!

If I try to build my test app for x64 rather than x86, I get complaints that the symbols without underscores are missing.

1>main.obj : error LNK2019: unresolved external symbol lua_close referenced in function main
1>main.obj : error LNK2019: unresolved external symbol lua_tolstring referenced in function main
1>main.obj : error LNK2019: unresolved external symbol lua_pcallk referenced in function main
1>main.obj : error LNK2019: unresolved external symbol luaL_openlibs referenced in function main
1>main.obj : error LNK2019: unresolved external symbol luaL_loadfilex referenced in function main
1>main.obj : error LNK2019: unresolved external symbol luaL_newstate referenced in function main


So, have you ended up building your version of the library for x64 and then tried to use it with an x86 test app?

Andy
Last edited on
oh yea, I was using VS2012 x64 cross tool cmd, didnt think that this could cause the problem, will try to do it again with x86

edit: works perfectly! thanks!: )
Last edited on
Topic archived. No new replies allowed.