0

I have an rpcgen generated file 'api_svc1.c' The file contains the following line:

local = (char *(*)(char *, struct svc_req *)) createacct_5_svc;

'createacct_5_sv' is declared in 'api.h' as

createAcctResult * createacct_5_svc();

But even after includeing the header file 'api.h', I get the following error:

api_svc1.c:90: undefined reference to `createacct_5_svc'

Aby suggestions?

Blackforest
  • 1,009
  • 2
  • 11
  • 18

1 Answers1

1

I suspect if you have "api.h", then you also have "api.c", in which case you have to link your api.c file to ap_svc1.c. Note that the error is not a compiler error complaining about a missing header; it's a linker error complaining about a not found (irresolvable) symbol after compiling to object code at the linking phase.

  • Hi H2CO3, we don't have an api.c here. rpcgen utility generates api server stub file, api client stub file and an api header (api.h). – Blackforest Jun 28 '12 at 06:34
  • 1
    You have to have a .c file in which you have the function. You can maybe use the `grep` utiliy to search for its name in .c files, then use your compiler to link it. –  Jun 28 '12 at 06:41
  • then where is the implementation of that function? api.h contains only the prototype, the implementation must be in a .c file somewhere, typically api.c. if you don't have it, then you won't be able to link to that function. – LeleDumbo Jun 28 '12 at 06:42
  • The function definition is present in api client stub file generated by rpcgen. This is a C file. – Blackforest Jun 28 '12 at 06:44
  • Then link to that file along with the file you have the error in, and that should be fine. –  Jun 28 '12 at 06:57
  • Hi H2CO3, If I link the api client stub file which contains the function definition, I get the error "multiple definition of `createacct_5' " – Blackforest Jun 28 '12 at 07:38
  • You're doing something *really* wrong. If you get a "Multiple definition" error now, you should not have got an "Undefined reference" error before, without linking it... –  Jun 28 '12 at 07:42
  • Maybe you're accidentally `#include`ing a .c file as well? –  Jun 28 '12 at 07:43