2014-02-18 94 views
1

我試圖做一個Lua模塊與Visual Studio 2013,主ccp是here以及module.hpp和其他包括是hereLua模塊與Visual Studio

我改變了主中共刪除不需要的包含文件和兩個不需要的功能,所以我得到這樣的:

#include <lua.hpp> 
#include <GeoIP.h> 
#include "module.hpp" 

static GeoIP * geoip = NULL; 

static int load_geoip_database(lua_State * L) 
{ 
    const char * filename = luaL_checkstring(L, 1); 
    if (geoip) GeoIP_delete(geoip); 
    geoip = GeoIP_open(filename, GEOIP_MEMORY_CACHE); 
    lua_pushboolean(L, geoip != NULL); 
    return 1; 
} 

static int ip_to_country(lua_State * L) 
{ 
    if (!geoip) return luaL_error(L, "missing GeoIP database"); 
    const char * ipaddr = luaL_checkstring(L, 1); 
    const char * country = GeoIP_country_name_by_addr(geoip, ipaddr); 
    lua_pushstring(L, (country ? country : "")); 
    return 1; 
} 

static int ip_to_country_code(lua_State * L) 
{ 
    if (!geoip) return luaL_error(L, "missing GeoIP database"); 
    const char * ipaddr = luaL_checkstring(L, 1); 
    const char * code = GeoIP_country_code_by_addr(geoip, ipaddr); 
    lua_pushstring(L, (code ? code : "")); 
    return 1; 
} 

static int shutdown_geoip(lua_State * L) 
{ 
    GeoIP_delete(geoip); 
    geoip = NULL; 
    return 0; 
} 

namespace lua{ 
    namespace module{ 

     void open_geoip(lua_State * L) 
     { 
      static luaL_Reg functions[] = { 
       { "load_geoip_database", load_geoip_database }, 
       { "ip_to_country", ip_to_country }, 
       { "ip_to_country_code", ip_to_country_code }, 
       { NULL, NULL } 
      }; 

      luaL_register(L, "geoip", functions); 
      lua_pop(L, 1); 

      lua::on_shutdown(L, shutdown_geoip); 
     } 

} //namespace module 
} //namespace lua 

Visual Studio中拋出我下面的錯誤:

1>------ Build started: Project: GeoIP, Configuration: Release Win32 ------ 
1> Main.cpp 
1>Main.obj : error LNK2001: unresolved external symbol _GeoIP_delete 
1>Main.obj : error LNK2001: unresolved external symbol _luaL_checklstring 
1>Main.obj : error LNK2001: unresolved external symbol _luaL_register 
1>Main.obj : error LNK2001: unresolved external symbol _lua_pushstring 
1>Main.obj : error LNK2001: unresolved external symbol _GeoIP_country_name_by_addr 
1>Main.obj : error LNK2001: unresolved external symbol _lua_settop 
1>Main.obj : error LNK2001: unresolved external symbol "void __cdecl lua::on_shutdown(struct lua_State *,int (__cdecl*)(struct lua_State *))" ([email protected]@@[email protected]@[email protected]@Z) 
1>Main.obj : error LNK2001: unresolved external symbol _GeoIP_country_code_by_addr 
1>Main.obj : error LNK2001: unresolved external symbol _GeoIP_open 
1>Main.obj : error LNK2001: unresolved external symbol _luaL_error 
1>Main.obj : error LNK2001: unresolved external symbol _lua_pushboolean 
1>C:\Users\User\Documents\Visual Studio 2013\Projects\Win32Project1\Release\GeoIP_win32.dll : fatal error LNK1120: 11 unresolved externals 
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ========== 

,我不知道錯誤的含義是什麼,這個模塊以前是由別人構建的,所以代碼應該是可以的。

回答

3

看起來你忘了配置你的版本,以便鏈接器知道鏈接到你的模塊的庫。看起來你應該鏈接到GeoIP DLL,當然還有Lua DLL。在項目的屬性對話框中,查找Linker | General | Additional Library Directories,它必須指示Lua DLL所在的文件夾以及GeoIP DLL所在的文件夾。然後看看Linker | Input | Additional Dependencies,它必須指出Lua DLL的Lua輸出庫的名稱(例如lua51.lib),並且GeoIP也是如此(類似於libgeoip.lib)。