【发布时间】:2014-03-18 23:37:18
【问题描述】:
我正在尝试使用 Visual Studio 2013 制作 Lua 模块,主 ccp 是 here 以及 module.hpp,另一个包含是 here。
我更改了主 ccp 以删除一个不需要的包含文件和两个不需要的函数,所以我得到了这个:
#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 *))" (?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 ==========
而且我不知道错误是什么意思,该模块是其他人之前构建的,所以代码应该没问题。
【问题讨论】: