4

What does it mean to have undefined symbols?

There are no errors in the code files themselves and I am NOT using any external libraries.

I DID add a typedef NS_ENUM prior to this linker error occurring.

Where do I add this -v to see invocation?

Here is the error message:

Undefined symbols for architecture x86_64:
  "_OBJC_IVAR_$_UIViewController._parentViewController", referenced from:
      -[PEPI_LessonController setParentViewController:] in PEPI_LessonController.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Guido Anselmi
  • 3,872
  • 8
  • 35
  • 58

3 Answers3

4

"Undefined Symbols"

Building source code files to an executable file consist of at least two steps:

  1. Compile the source code files to intermediate binary files (often called xyz.o).
  2. Link the intermediate binary files to the final executable file.

The error message "undefined symbols" is a linker message. It may appear even though the compilation process was successful without notice. The linker organizes final memory address relations and it replaces symbols that the compiler had to assume they would be valid later, if all parts of the code would be available. Without this, no modularization would be possible at all.

-v to see invocation

If you build your application in Xcode, then Xcode calls all the compile and link commands for you (CompileC, Ln, Clang ...). But remember that a typical IDE runs only the commands you could run by yourself in the shell. Theoretically, you could develop big applications only in a text editor and a shell. So I suggest take some time and try to copy paste some commands listed in the Xcode build report to a shell :-) You'll learn a lot about the backgrounds. Therefore, in my opinion, -v to see invocation is used while invoking the command in the shell - or in the build settings, if you wish permanently more information.

"External libraries"

Finally, try to clarify "external libraries". To look at the most simple example: even if you write a simple C program and you want to know something trivial like the length of a string, you'll include <glibc.h>. Now this is an external library. It's external to your program code. Are you sure you haven't included external libraries?

Solving linker problems

Linker errors are often confusing and somehow difficult, because details of the linked modules tend to be out of sight. You may find many hints if you enter the error message in a search engine. For example, have a look at here:

Undefined symbols for architecture armv7: "_SCNetworkReachabilityCreateWithAddress"

Even if all components are found for linking, all paths are known etc, they may have the wrong version or else.

Community
  • 1
  • 1
peter_the_oak
  • 3,529
  • 3
  • 23
  • 37
2

In my case I had forgotten to add the .m file to all the same targets as the .h and that's what caused this issue. In case it helps anyone thought I'd mention here... double check your target memberships!

Harout360
  • 899
  • 1
  • 9
  • 14
1

It means it can't find the property parentViewController and method setParentViewController when linking your object files files. The most common cause for these types of errors is not linking a library or framework in your projects target. UIViewController is part of UIKit so I'd be surprised if it's not already linked. Is this an OSX project and your trying to use UIViewcontroller instead of NSViewController?

Brandon
  • 2,387
  • 13
  • 25
  • It is an iOS (iPad) project. I am actually subclassing UIViewController, not sure if that means anything. It built this morning, but after altering some code in a master controller (responsible for choosing the right view) I started to get this. I DID add a **`typedef NS_ENUM`** prior to this linker error occurring. – Guido Anselmi Jun 30 '14 at 20:23
  • @Guido Anselmi: Check Xcode > Your project > Targets > "Build Phases" > "Link Binary with Libraries". Majority of linker problems is solved there. – peter_the_oak Jun 30 '14 at 20:27
  • What might I need to add? I am not using any external libraries in my project. Does the NS_Enum class exist in an external lib? – Guido Anselmi Jun 30 '14 at 20:28
  • Make sure UIKit.framework is listed. If not add it. NS_Enum isn't a class and shouldn't make a difference. – Brandon Jun 30 '14 at 20:32