Lua无法加载VC ++ DLL

时间:2014-10-12 01:33:19

标签: c visual-c++ dll lua

我使用Visual Studio C / C ++工具链将我的 litertools 项目编译为.dll,并正确导出lua_openlitertools函数:

PS> dumpbin /exports .\bin\lib\litertools.dll
Microsoft (R) COFF/PE Dumper Version 14.00.22013.1

Dump of file .\bin\lib\litertools.dll    

  Section contains the following exports for litertools.dll

    00000000 characteristics
    5439D35E time date stamp Sun Oct 12 12:03:26 2014
        0.00 version
           1 ordinal base
           1 number of functions
           1 number of names  
    ordinal hint RVA      name

          1    0 000227AD luaopen_litertools = @ILT+1960(_luaopen_litertools) 
  Summary

        1000 .data
        2000 .idata
        6000 .rdata
        2000 .reloc
        1000 .rsrc
       44000 .text
       21000 .textbss

当我设置configure package.cpath然后通过执行以下操作时需要litertools dll:

CMD> lua -e "package.cpath=\".\\bin\\lib\\?.dll\"; require(\"litertools\")"

我收到以下错误

lua: error loading module 'litertools' from file '.\bin\lib\litertools.dll':
        The specified module could not be found.

stack traceback:
        [C]: in ?
        [C]: in function 'require'
        (command line):1: in main chunk
        [C]: in ?

调查一下,我通过require(loadlib.c)调试了调用,然后到了这里:

static void *ll_load (lua_State *L, const char *path, int seeglb) {
  HMODULE lib = LoadLibraryExA(path, NULL, LUA_LLE_FLAGS);
  (void)(seeglb);  /* not used: symbols are 'global' by default */
  if (lib == NULL) pusherror(L);
  return lib;
}

LoadLibraryExA的调用会返回NULL。我不确定为什么会发生这种情况,尽管我使用mingw-gcc编译了相同的库并且能够要求dll。

1 个答案:

答案 0 :(得分:0)

我发现通过使用

找不到依赖关系

http://www.dependencywalker.com/ enter image description here

将单元测试移动到单独的项目中并更正解决方案设置。