带visualstudio的Lua模块

带visualstudio的Lua模块,lua,visual-studio-2013,Lua,Visual Studio 2013,我正在尝试用Visual Studio 2013制作一个Lua模块,主要ccp与module.hpp一起,另一个包含 我更改了主ccp以删除一个不需要的include文件和两个不需要的函数,因此得到了以下结果: #include <lua.hpp> #include <GeoIP.h> #include "module.hpp" static GeoIP * geoip = NULL; static int load_geoip_database(lua_State

我正在尝试用Visual Studio 2013制作一个Lua模块,主要ccp与module.hpp一起,另一个包含

我更改了主ccp以删除一个不需要的include文件和两个不需要的函数,因此得到了以下结果:

#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

我不知道这些错误是什么意思,这个模块是别人以前构建的,所以代码应该是可以的

看起来您忘记配置构建,因此链接器知道要链接到模块的库。看起来您应该链接到geoipdll,当然还有luadll。在项目的“属性”对话框中,查找
链接器|常规|其他库目录
,它必须指明Lua DLL所在的文件夹以及GeoIP DLL所在的文件夹。然后查看
Linker | Input | Additional Dependencies
,它必须指明Lua DLL的Lua导出库的名称(例如
lua51.lib
),GeoIP也是如此(类似于
libgeoip.lib

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 *))" (?on_shutdown@lua@@YAXPAUlua_State@@P6AH0@Z@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 ==========