Search code examples
c++xcodeclang++xcode10

Xcode 10.0: Linker command failed with exit code 1 (use -v to see invocation)


Created a new Xcode cpp project with the code below and it gives me the clang error "Linker command failed with exit code 1".

I tried running this an existing Xcode project and it builds successfully but when I do it in the existing one or create a new project and copy paste this code over, same issue. I've also tried researching other StackOverflow posts on this error and there doesn't seem to be any specific way on how to find a solution.

#include <iostream>
#include <stdio.h>

using namespace std;

class LList{
private:
    //Represents each node in the LL
    struct ListNode{
        int data;
        ListNode* next;
    };
    typedef struct ListNode* nodePtr;
    nodePtr head, current, temp;

public:
    LList();
    void Insert(int addData) {
        nodePtr n = new ListNode;
        n->next = NULL;
        n->data = addData;
        if(head != NULL){
            current = head;
            while(current->next != NULL){
                current = current->next;
            }
            current->next = n;
        }
        else{
            head = n;
        }
    };

    void Remove(int removeData) {
        nodePtr delPtr = NULL;
        temp = head;
        current = head;
        while(current != NULL && current->data != removeData){
            temp = current;
            current = current->next;
        }
        if(current == NULL){
            cout << removeData << " was not in the list\n";
            delete delPtr;
        }
        else{
            delPtr = current;
            current = current->next;
            temp->next = current;
            if(delPtr == head){
                head = head->next;
                temp = NULL;
            }
            delete delPtr;
            cout << "The value " << removeData << " was deleted\n";
        }
    };

    void PrintList() {
        current = head;
        while(current != NULL){
            cout << current->data << " - ";
            current = current->next;
        }
        cout << "\n";
    };

    LList::ListNode* middleNode(LList::ListNode* head) {
        LList::ListNode* fastPtr = head;
        LList::ListNode* slowPtr = head;
        while(fastPtr->next != NULL){
            fastPtr = fastPtr->next;
            if(fastPtr->next != NULL){
                fastPtr = fastPtr->next;
            }
            slowPtr = slowPtr->next;
        }
        return slowPtr;
    };
};


int main() {
    LList Aj;
    Aj.Insert(5);
    Aj.Insert(8);
    Aj.Insert(10);
    Aj.PrintList();
    Aj.Remove(8);
    Aj.PrintList();
    Aj.Remove(5);
    Aj.PrintList();
}

Solution

  • LList() default constructor is declared, but never implemented.