Search code examples
c++xcodefunctionvirtual

Linker Command Fail in Xcode with Pure Virtual Objects


I'm a n00b so correct me on anything.

I've been working on this for a couple days and have done research but can't seem to solve the issue. This is for a programming class that mainly uses Visual Studio and many of my fellow classmates didn't have a problem. Although, I'm on Xcode so maybe it has something to do with that. Basically, I'm creating a Pure Virtual objects called Geometric_Object with child classes Circle.h and Rectangle.h, however when I run the code I get the following error:

Undefined symbols for architecture x86_64:
"GeometricObject::GeometricObject()", referenced from:
Circle::Circle() in main.o
Rectangle::Rectangle() in main.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

I'm beyond lost. Because I don't have enough reputation points I can't post all the links so I had to compress them as one on Dropbox. Hopefully someone can bypass this for me so nobody is afraid to unzip the contents.

https://dl.dropboxusercontent.com/u/82764116/Xcode.zip


Solution

  • The problem is exactly what the error says. You haven't defined GeometricObject::GeometricObject(). You also haven't defined many other methods in GeometricObject, like the destructor, getColor, setColor etc.

    I'm not sure where you think the definitions for these functions are, but they aren't in the code you've linked to.

    You have defined (for instance) Rectangle::Rectangle(). Just define GeometricObject::GeometricObject() in the same way (and all the other missing definitions).