2

I saw this post here: ld: undefined symbol vs ld: undefined reference and I don't think it really talks about what the differences are between these 2 linker errors.

I usually get undefined reference linker errors when the linker can't find the definition of something (or I declared it and forgot to define it), but it seems undefined symbol serves the same purpose (the answer in the above linked post gives an example that seems to be aligned with when undefined reference arises, but maybe I'm missing some subtlety here?), so I'm a bit confused. Can someone clarify, perhaps with examples, of when each one arises during linking?

Edit: I didn't know the terminology for linker errors could be dependent on if using gnu, clang, etc...

In my case, I saw the undefined symbol error when using clang++ and the error was

stderr: ld.lld: error: undefined symbol: custom::linear::adapt()

Is undefined symbol the clang counterpart to gnu's undefined reference?

24n8
  • 1,898
  • 1
  • 12
  • 25
  • 2
    Are you perhaps thinking about "undefined reference" (as emitted by the GNU ld linker in e.g. Linux) versus "unresolved external symbol" (as emitted by the MSVC linker in Windows)? – Some programmer dude Apr 25 '22 at 12:49
  • @Someprogrammerdude Oh I had thought these linker error terminology were uniform across different linkers. I just checked my codebase and it runs a continuous integration test with clang++ `clang++: error: linker command failed with exit code 1 (use -v to see invocation)` and the error was `stderr: ld.lld: error: undefined symbol: custom::linear::adapt()` – 24n8 Apr 25 '22 at 12:54
  • [This](https://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix) might be a duplicate. The first answer shows GCC and MSVC output for the same code, one says reference, the other says symbol. I imagine clang also just uses "symbol" – ChrisMM Apr 25 '22 at 12:59
  • @ChrisMM Is there a difference between `undefined symbol` and `unresolved external symbol`? – 24n8 Apr 25 '22 at 13:02
  • 3
    I don't think there is a difference. Some compilers call it one or the other depending on the linker used. – drescherjm Apr 25 '22 at 13:08

0 Answers0