【问题标题】:Xcode 10.0: Linker command failed with exit code 1 (use -v to see invocation) [duplicate]Xcode 10.0:链接器命令失败,退出代码为 1(使用 -v 查看调用)[重复]
【发布时间】:2019-12-18 14:54:39
【问题描述】:

使用下面的代码创建了一个新的 Xcode cpp 项目,它给了我一个 clang 错误“链接器命令失败,退出代码 1”。

我尝试在现有的 Xcode 项目中运行此项目并成功构建,但是当我在现有项目中执行此操作或创建新项目并复制粘贴此代码时,同样的问题。我还尝试研究有关此错误的其他 StackOverflow 帖子,但似乎没有任何具体方法可以找到解决方案。

#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();
}

【问题讨论】:

    标签: c++ xcode clang++ xcode10


    【解决方案1】:

    LList() 默认构造函数已声明,但从未实现。

    【讨论】:

    • 啊,我不敢相信我错过了。我需要删除该构造函数或使用初始值定义它。欣赏它,伊戈尔!
    猜你喜欢
    • 1970-01-01
    • 2023-03-03
    • 1970-01-01
    • 2023-03-28
    • 2018-08-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多