c++objective-ciphonexcode

Issue with Duplicate symbol in link phase of project build in Xcode


I've been building a game application for iOS. The application was working fairly well, but I've done a fairly large restructure today to be a little more model-view-controller 'compliant'.

I've built the main game engine in C++, but use Objective-C for managing the viewControllers, views etc.

Now, when I compile the project, I'm getting an error in the link phase. Details are below:

ld: duplicate symbol ApplicationEngine::OnFingerUp(Vector2) in /Users/Dan/Library/Developer/Xcode/DerivedData/BlackHoles-exrlidtstxzdtsbyjghgquhlsqul/Build/Intermediates/BlackHoles.build/Debug-iphonesimulator/BlackHoles.build/Objects-normal/i386/ApplicationEngine.o and /Users/Dan/Library/Developer/Xcode/DerivedData/BlackHoles-exrlidtstxzdtsbyjghgquhlsqul/Build/Intermediates/BlackHoles.build/Debug-iphonesimulator/BlackHoles.build/Objects-normal/i386/AppDelegate.o for architecture i386 collect2: ld returned 1 exit status Command /Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/g++-4.2 failed with exit code 1

OnFingerUp is a function within my C++ ApplicationEngine, and gets called from the viewController.

Is the problem likely to be caused by some confusion in my #includes / #imports?

My AppDelegate file needs to #include a MainViewController file to set up the initial viewController. The MainViewController in turn #includes the ApplicationEngine file to instantiate that class. ApplicationEngine contains the OnFingerUp method. The OnFingerUp method is then called from MainViewController when I get a touch input. Could this sequence of includes be causing the duplicate?

I've noticed that if I temporarily remove the OnFingerUp method from the app completely, then I get the same issue with another method within the ApplicationEngine.

There aren't any errors or warnings as the individual files compile. I've also tried to Clean All and recompile, but no joy.

Does anyone have any suggestions as to how I could approach solving the issue? Thanks, Dan.


Solution

  • I can think of 3 causes for this: 1) Accidentally #including a .cpp file, 2) forgetting #ifndef guards in the header file, 3) forgetting inline when writing the method definition in a header file.