c++ - symbol not found AKA undefined symbol -
most of people work on unix face irritating error often. , times take less time solve , take hell lot of time.
even faced regularly , need document or article regarding specific error in c/c++
what cases there might symbol not found/undefined symbol error.
could me know cases?
the error not related unix/windows/any other os, rather languages themselves. rather simple diagnose information compilers provide. tell symbol missing , being used. main reasons symbol missing are:
- you have declared never defined it
- you have defined it, did not add compiled symbol (object file/library) linker
- it external , forgot link library, or linking invalid version, or in wrong order.
the first 1 little trickier if intended define symbol did not match declaration (declared void foo( int, double );
, defined void foo( double, int )
. other cases, compiler tell exact signature looking for, make sure have defined that symbol, , not close or similar, particular corner case can if using different calling conventions in declaration , definition, similar in code.
in case of libraries external code complexity in identifying library needs linked symbol added, , comes documentation of lib. beware static libraries order of libs in linker command line affects result.
to in finding symbols defined can use nm
(gcc, common among unix systems). can run nm
against object files/libs linking , search symbol linker complaining about. in cases order makes difference (i.e. symbol there, linker skipped it).
at runtime (thanks matthieu m. pointing out) might have similar issues dynamic libraries, if wrong version of library found in ld_library_path might end library not have required symbol.
Comments
Post a Comment