Undefined reference/unresolved external symbol errors in C++/C/Objective-c and ways to solve/avoid them.

Prafulla Singh
4 min readMay 28, 2018

These specific errors occur at the last stage of Compilation, The stage is also called linking stage. As the name suggest all the code(implementation files) has been converted into object file or libraries. Now compiler wants to link them all together.

for a small example, A developer has defined one symbol SYM in a class TEST1 and you declared it in class TEST2. Linking phase has the responsibility to make sure call to that symbol finds valid symbol and link to it. In case that symbol not found TEST1(due to various reasons Will talk about it in detail) we will get such error.

Following are some most common error people do result in such errors:

Forgot to Add Appropriate Libraries/object files:

This is one of the most common mistake, When a user does use headers of the library but forget to add related Library/object files or has an invalid path. In case of using development tools like Xcode forget to add library search path. So At the linking time, no such symbol found hence the error.

In Xcode, Go to Build Setting => Go to Library search Path => give path to the library. Similarly, GO to header search Path => give Path to the header

In terminal/Makefile, you have to specify all object files and all libraries using -l while creating a final executable/library. so the syntax…

--

--

Prafulla Singh
Prafulla Singh

Responses (1)