【发布时间】:2017-10-05 13:37:25
【问题描述】:
我正在做一个 rpc 服务器/客户端项目。硬编码的端点版本运行良好,现在我想让服务器动态设置端点。
我做了一些研究,我需要使用RpcNsBindingExport()函数将名称服务数据库导出到服务器,然后客户端可以获得可用的绑定信息。服务器代码可以编译,但运行服务器时出现错误。错误消息说:
函数 _main 中引用的 LNK2019 未解析的外部符号 __imp__RpcNsBindingExportA@20
这是我的 server.cpp 的代码:
main(){
//choose protocol sequence
status = RpcServerUseProtseq(
pszProtocolSequence,
RPC_C_PROTSEQ_MAX_REQS_DEFAULT,
pszSecurity
);
if (status) exit(status);
//get binding info for server
RPC_BINDING_VECTOR *binding_vector;
status = RpcServerInqBindings(&binding_vector);
//Export to a name service database for advertising
status = RpcNsBindingExport(
RPC_C_NS_SYNTAX_DEFAULT,
(unsigned char *)"hostname",
midl_v1_0_s_ifspec,
binding_vector,
NULL
);
if (status) exit(status);
//reg server
status = RpcEpRegister(
hello_v1_0_s_ifspec,
binding_vector,
NULL,
(unsigned char *)annotion
);
//listen
if (status) exit(status);
status = RpcServerListen(cMinCalls,
RPC_C_LISTEN_MAX_CALLS_DEFAULT,
fDontWait);
if (status) exit(status);
}
rpcrt4.lib 和 rpcns4.lib 都在项目中链接。我不知道是否缺少任何东西,或者RpcNsBindingExport() 的用法可能是错误的。
感谢您的任何建议和想法。
【问题讨论】:
-
请提供minimal reproducible example。特别是您显示的代码中没有
main,但这似乎是错误所在 -
您说“我运行服务器时出错”,但错误是链接器错误...
-
"不知道有没有遗漏,或者
RpcNsBindingExport()的用法不对"这样的错误(unresolved external symbol i>) 在库函数调用上,最常见的原因是没有链接到定义函数的库 (.lib),而不是因为它的一些奇怪用法(如果是 - 你会得到编译错误,而不是链接错误)。请详细说明“rpcrt4.lib 和 rpcns4.lib 都包含在项目中。”是什么意思(“包含”这个词是什么意思? )。 -
来自 MSDN 文档:注意此函数在 Windows Vista 及更高版本的操作系统上不受支持。 也许库不包含该函数?