Mac Linker Errors

I’m experiencing some unusual linker errors in C++ compiling on a Mac.

I have a subclass of ACharacter called ABaseNPCCharacter, and then two subclasses of ABaseNPCCharacter called AFriendCharacter and AEnemyCharacter. As of right now, AFriendCharacter is currently an empty subclass, but ABaseNPCCharacter and AEnemyCharacter both add and override functions from ACharacter.

Things were working quite well at first. I had overridden Tick(), but when I overrode PostInitializeComponents, it began throwing errors.

In ABaseNPCCharacter.h, I added:

    virtual void PostInitializeComponents();

and in ABaseNPCCharacter.cpp, I added:

void ABaseNPCCharacter::PostInitializeComponents()
{
    Super::PostInitializeComponents();
    
    if (WaypointAutoBuildTag != NULL)
    {
        // TODO: Build waypoint array from tag
    }
    
}

Once I add these, I get the following error:

ExternalBuildToolExecution RepublicSniperAIEditor\ -\ Mac
    cd /Users/Shared/UnrealEngine/4.4
    export ACTION=
    /Users/Shared/UnrealEngine/4.4/Engine/Build/BatchFiles/Mac/RocketBuild.sh RepublicSniperAIEditor macosx DebugGame /Users//Dropbox\ (MartianCraft)/RepublicSniperAI/RepublicSniperAI.uproject

Setting up Mono
Building RepublicSniperAIEditor...
Compiling with Mac SDK 10.9
Parsing headers for RepublicSniperAIEditor
Reflection code generation finished for RepublicSniperAIEditor and took 3.812
Performing 11 actions (max 16 parallel jobs)
[9/11] Compile FriendController.cpp
[5/11] Compile BTDecorator_IsMoving.cpp
[6/11] Compile BTTask_FindNextWaypoint.cpp
[2/11] Compile EnemyController.cpp
[1/11] Compile BaseNPCController.cpp
[10/11] Compile FriendCharacter.cpp
[8/11] Compile BaseNPCCharacter.cpp
[4/11] Compile RepublicSniperAI.generated.cpp
[7/11] Compile BTTask_MoveToNextWaypoint.cpp
[3/11] Compile EnemyCharacter.cpp
[11/11] Link UE4Editor-RepublicSniperAI-Mac-DebugGame.dylib
Undefined symbols for architecture x86_64:
  "ABaseNPCCharacter::PostInitializeComponents()", referenced from:
      vtable for AEnemyCharacter in EnemyCharacter.cpp.o
      vtable for AFriendCharacter in FriendCharacter.cpp.o
  "vtable for ABaseNPCCharacter", referenced from:
      ABaseNPCCharacter::ABaseNPCCharacter(FPostConstructInitializeProperties const&) in BaseNPCCharacter.cpp.o
      ABaseNPCCharacter::~ABaseNPCCharacter() in EnemyCharacter.cpp.o
      ABaseNPCCharacter::~ABaseNPCCharacter() in FriendCharacter.cpp.o
  NOTE: a missing vtable usually means the first non-inline virtual member function has no definition.
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
-------- End Detailed Actions Stats -----------------------------------------------------------
ERROR: UBT ERROR: Failed to produce item: /Users//Dropbox (MartianCraft)/RepublicSniperAI/Binaries/Mac/UE4Editor-RepublicSniperAI-Mac-DebugGame.dylib
Cumulative action seconds (16 processors): 0.00 building projects, 44.93 compiling, 0.00 creating app bundles, 0.00 generating debug info, 0.22 linking, 0.00 other
UBT execution time: 12.91 seconds
Command /Users/Shared/UnrealEngine/4.4/Engine/Build/BatchFiles/Mac/RocketBuild.sh failed with exit code 2

I tried switching compilers (Clang, GCC), C++ versions (C++14, C++11, Compiler Default), and played with different linker options and flags, but none solved the problem. I googled around and asked in the forums, but could not find a solution. So, for the time being, I commented the function out so I could continue to work.

Then, I went to add a new function to the class that’s NOT overriding a parent class. I added this to AEnemyCharacter.h:

    UFUNCTION(BlueprintCallable, Category=Alertness)
    FString AlertStatusString();

and this to AEnemyCharacter.cpp:

FString AEnemyCharacter::AlertStatusString()
{

    EEnemyAlertStatus::Type AlertStatus = GetAlertStatus();
    return GetNameForAlertStatus(AlertStatus);
}

(GetNameForAlertStatus() is an inline function to return a string for an enum type)

When I compile this, I get similar linker errors:

ExternalBuildToolExecution RepublicSniperAIEditor\ -\ Mac
    cd /Users/Shared/UnrealEngine/4.4
    export ACTION=
    /Users/Shared/UnrealEngine/4.4/Engine/Build/BatchFiles/Mac/RocketBuild.sh RepublicSniperAIEditor macosx DebugGame /Users//Dropbox\ (MartianCraft)/RepublicSniperAI/RepublicSniperAI.uproject

Setting up Mono
Building RepublicSniperAIEditor...
Compiling with Mac SDK 10.9
Parsing headers for RepublicSniperAIEditor
Reflection code generation finished for RepublicSniperAIEditor and took 3.377
Performing 11 actions (max 16 parallel jobs)
[7/11] Compile BTTask_MoveToNextWaypoint.cpp
[10/11] Compile FriendCharacter.cpp
[9/11] Compile FriendController.cpp
[3/11] Compile EnemyCharacter.cpp
[5/11] Compile BTDecorator_IsMoving.cpp
[6/11] Compile BTTask_FindNextWaypoint.cpp
[8/11] Compile BaseNPCCharacter.cpp
[2/11] Compile EnemyController.cpp
[4/11] Compile RepublicSniperAI.generated.cpp
[1/11] Compile BaseNPCController.cpp
[11/11] Link UE4Editor-RepublicSniperAI-Mac-DebugGame.dylib
Undefined symbols for architecture x86_64:
  "AEnemyCharacter::AlertStatusString()", referenced from:
      AEnemyCharacter::execAlertStatusString(FFrame&, void*) in RepublicSniperAI.generated.cpp.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
-------- End Detailed Actions Stats -----------------------------------------------------------
ERROR: UBT ERROR: Failed to produce item: /Users//Dropbox (MartianCraft)/RepublicSniperAI/Binaries/Mac/UE4Editor-RepublicSniperAI-Mac-DebugGame.dylib
Cumulative action seconds (16 processors): 0.00 building projects, 40.48 compiling, 0.00 creating app bundles, 0.00 generating debug info, 0.17 linking, 0.00 other
UBT execution time: 11.74 seconds
Command /Users/Shared/UnrealEngine/4.4/Engine/Build/BatchFiles/Mac/RocketBuild.sh failed with exit code 2

I’ve tried using different function names but, again, nothing I do seems to change the linker error.

I’ve uploaded a test project where the compiler error happens. If you download this and compile it on a Mac, you should see the problem:

[Test Scaffold][1]

Any thoughts or suggestions about what’s causing these linker issues would be greatly appreciated.

[1]:

We figured it out. The EnemyCharacter.cpp class had gotten duplicated so was being compiled twice.