Solved

RPC linking problems

Posted on 2006-06-12
8
1,259 Views
Last Modified: 2012-08-13
Hi,

I'm having problems linking a Test RPC application in VS .NET 2003. I get the following errors:

TestRPC error LNK2001: unresolved external symbol _NdrServerCall2@4
TestRPC error LNK2001: unresolved external symbol _Output
TestRPC error LNK2019: unresolved external symbol __imp__RpcServerListen@12 referenced in function _main
TestRPC error LNK2019: unresolved external symbol __imp__RpcServerRegisterIf@12 referenced in function _main
TestRPC error LNK2019: unresolved external symbol __imp__RpcServerUseProtseqEpA@16 referenced in function _main

It's probably something to do with the name mangling but I cant quite figure it out. Any ideas?
0
Comment
Question by:spiffles
  • 4
  • 3
8 Comments
 
LVL 12

Accepted Solution

by:
rajeev_devin earned 60 total points
ID: 16883794
You need to add Rpcrt4.lib in your linker settings for there functions

TestRPC error LNK2019: unresolved external symbol __imp__RpcServerListen@12 referenced in function _main
TestRPC error LNK2019: unresolved external symbol __imp__RpcServerRegisterIf@12 referenced in function _main
TestRPC error LNK2019: unresolved external symbol __imp__RpcServerUseProtseqEpA@16 referenced in function
0
 
LVL 12

Expert Comment

by:rajeev_devin
ID: 16883799
>> NdrServerCall2
for this function also you need some .lib file. Check it out.
I never used this function so i don't know the name of .lib file for this function.

Good luck !

0
 

Author Comment

by:spiffles
ID: 16883906
Thanks for that. I have a function called output in my idl file:

   void Output(
      [in] handle_t hBinding,
      [in, string] const char* szOutput);

And the output implementation in TestRPC.cpp is:

#include "OutputIf.h"

void Output(handle_t hBinding, const char* szOutput)
{
      std::cout << szOutput << std::endl;
}

Any ideas why this isn't linking?
0
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 
LVL 12

Expert Comment

by:rajeev_devin
ID: 16883966
What is the error ?
0
 

Author Comment

by:spiffles
ID: 16884035
The same:
TestRPC error LNK2001: unresolved external symbol _Output
0
 
LVL 17

Expert Comment

by:rstaveley
ID: 16888284
The lack of name mangling suggests that the calling code expects C linkage rather than name-mangled C++ linkage.

Change it as follows in the .cpp file for C-linkage:

extern "C" void Output(handle_t hBinding, const char* szOutput)
{
     std::cout << szOutput << std::endl;
}

In the header file prototype it thus:

#ifdef __cplusplus
extern "C"
#endif
    void Output(handle_t hBinding, const char* szOutput);
0
 

Author Comment

by:spiffles
ID: 16890958
The .h file is generated from the IDL file and I'd prefer not to edit the generated file:

In the generated spec file:
void Output(
    /* [in] */ handle_t hBinding,
    /* [string][in] */ const unsigned char *szOutput);

0
 

Author Comment

by:spiffles
ID: 16891023
Nevermind i found the problem...unsigned
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now