找到你要的答案

Q:Windows RPC programming error: LNK 2019 unresolved external symbol RPCServerListen

Q:Windows RPC编程错误:lnk 2019未解决的外部符号rpcserverlisten

I am learning C Windows RPC programming. Here is the source code for a dummy RPC Server I wrote and compiled without errors:

#include <stdio.h>
#include "md5_h.h"
#include "rpc.h"
#include "rpcndr.h"

int main() {
  RPC_STATUS status;

  status = RpcServerUseProtseqEp(
    (RPC_WSTR)("ncacn_ip_tcp"),
    RPC_C_PROTSEQ_MAX_REQS_DEFAULT,
    (RPC_WSTR)("9191"),
    NULL);
if (status) { exit(status); }

status = RpcServerRegisterIf(
    md5_v1_0_c_ifspec,
    NULL,
    NULL);
if (status) { exit(status); }

status = RpcServerListen(
    1,
    RPC_C_LISTEN_MAX_CALLS_DEFAULT,
    FALSE);
if (status) { exit(status); }

return 0;
}

void __RPC_USER midl_user_free(void* p) {
  free(p);
}

void md5(const unsigned char* szMsg) {
  printf("voila %s\n", szMsg);
}

The midl files get compiled without errors as well. The MIDL-compilation produces md5_s.c and md5_c.c as expected. Here is md5.idl file if needed:

[
uuid(D86FBC01-D6A7-4941-9243-07A4EC65E8CB),
    version(1.0),
]
interface md5
{
  void md5([in, string] const char* szMsg);
};

During the Linkage stage the following errors are produced:

LNK2019: unresolved external symbol __imp__RpcServerListen referenced in function main

I have same errors for every RPC-specific functions, such as RpcServerRegisterIf or RpcServerUseProtseqEp. I am using Microsoft Visual Studio 2013.

I think this comes from a missing include; but I can't figure which one. I tried to include rpc.h, without any change.

Do I have to include in my project the produced md5_s.c? I have tried so without resolving anything.

Thanks for helping!

我学习C++的Windows RPC编程。这里是源代码为一个虚拟的RPC服务器我写和编译没有错误:

#include <stdio.h>
#include "md5_h.h"
#include "rpc.h"
#include "rpcndr.h"

int main() {
  RPC_STATUS status;

  status = RpcServerUseProtseqEp(
    (RPC_WSTR)("ncacn_ip_tcp"),
    RPC_C_PROTSEQ_MAX_REQS_DEFAULT,
    (RPC_WSTR)("9191"),
    NULL);
if (status) { exit(status); }

status = RpcServerRegisterIf(
    md5_v1_0_c_ifspec,
    NULL,
    NULL);
if (status) { exit(status); }

status = RpcServerListen(
    1,
    RPC_C_LISTEN_MAX_CALLS_DEFAULT,
    FALSE);
if (status) { exit(status); }

return 0;
}

void __RPC_USER midl_user_free(void* p) {
  free(p);
}

void md5(const unsigned char* szMsg) {
  printf("voila %s\n", szMsg);
}

MIDL文件编译没有错误和。MIDL编译产生md5_s。C和C md5_c预期。这是md5.idl如果需要的文件:

[
uuid(D86FBC01-D6A7-4941-9243-07A4EC65E8CB),
    version(1.0),
]
interface md5
{
  void md5([in, string] const char* szMsg);
};

在联动阶段产生以下错误:

LNK2019: unresolved external symbol __imp__RpcServerListen referenced in function main

我有同样的错误每个RPC的特异功能,如rpcserverregisterif或rpcserveruseprotseqep。我使用微软Visual Studio 2013。

我认为这来自一个失踪的包括,但我不能确定哪一个。我想包括RPC的H,没有任何改变。

我要在我的项目包括生产md5_s。C?我试着不解决任何问题。

感谢帮助!

answer1: 回答1:

You need to link against Rpcrt4.lib. If you are using visual studio, add it in the Project -> Properties -> Configuration Properties -> Linker -> Input -> Additional Dependencies.

You need to link against Rpcrt4.lib. If you are using visual studio, add it in the Project -> Properties -> Configuration Properties -> Linker -> Input -> Additional Dependencies.

c  rpc