0

I have a static lib libTheLib.a (compiled by someone else). I am trying to link it with my program. One of the functions that this lib requires for linking is GetName. I have a function void GetName(char*, int) in my project, but the linker is still complaining the the symbol is not found. I am guessing that maybe the lib is looking for a function with a different signature. I tried using nm hoping it will reveal what exactly is being looked for, but all it says is

         U _GetName

which is not very helpful. Is there another way to find the signature of the symbol it is looking for? Or is the signature not part of the symbol, and it can actually link to any symbol of that name?

The lib is written in C, my program in C++, but the function is declared as

extern "C" GetName(char* c, int i) {...}

Also, this is using clang, not gcc, if it makes a difference (using XCode)

Baruch
  • 20,590
  • 28
  • 126
  • 201
  • In C, there's no name mangling, so you ain't easily finding out the function signature. WHat's the exact linker error? –  Jul 22 '13 at 07:25
  • @H2CO3 The error is: `Undefined symbols: "_GetName", referenced from: foo in libTheLib.a(bar.o) ld: symbol(s) not found – Baruch Jul 22 '13 at 07:32
  • Are you sure that it is indeed declared `extern "C"` when visible from the .cpp file? Seems like a name mangling issue. –  Jul 22 '13 at 07:35

1 Answers1

0

1) Are you sure that the function name and signature are correct?

2) Why

extern "C" GetName(char* c, int i) {...}

instead of

extern "C" GetName(char* c, int i);

?

Matteo Umili
  • 3,412
  • 1
  • 19
  • 31
  • 1) The function name is correct. The signature is exactly what I am trying to figure out. 2) Because it is the actual function, not a forward deceleration of it. the `...` just means there is more code there that is irrelevant to the current issue. – Baruch Jul 22 '13 at 08:56
  • @baruch Did you try with `extern "C" void GetName(char* c, int i);` ? – Matteo Umili Jul 25 '13 at 08:42
  • Yes, it is `void`. It was just a typo in the question. – Baruch Jul 25 '13 at 10:51