LD:架构x86_64 clang找不到符号:错误:链接器命令失败,出口代码1(使用-v to See

ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see

本文关键字:代码 出口 失败 使用 See to 命令 x86 架构 clang 找不到      更新时间:2023-10-16

我的第一篇文章之一,很抱歉任何格式错误:

我正在尝试创建一个简单的链接列表类,但是每当我尝试运行代码时,我都会遇到错误。我正在编写的另一个代码也没有共享任何独特的特征。我已经搜索了这个网站和其他论坛,大约一个月了,我找不到任何有助于解决方案的东西。这是错误:

架构X86_64的未定义符号:" linkedlist :: linkedlist()",从:      _ Main.o中的MainLD:符号(s)架构x86_64找不到符号clang:错误:Linker命令因出口代码1失败(使用-V查看调用)

很抱歉列出了长时间的代码,但我根本无法缩小问题。这是我的主():

#include <iostream>
#include "LinkedListHeader.h"
using namespace std;
// Driver
int main()
{
    // LinkedList instance
    LinkedList* obj = new LinkedList();
// Prompt user for number of inputs
int count;
cout << "How many items would you like to add to the list?" << endl;
cin >> count;
// For loop
for (int i = 0; i < count; i++)
{
    double value;
    cout << "Enter item " << i + 1 << ": ";
    cin >> value;
    obj->add(value);
}
// Call member function displayList() to... wait for it... display the list
obj->displayList();
// Prompt user for a search criteria
double search;
cout << "Enter a number to search for in the list: ";
cin >> search;
// If value is in the list then tell the user. If it ain't then don't
if(obj->isMember(search))
{
    cout << search << " is in the list!" << endl;
}
else
    cout << search << " is NOT in the list!" << endl;
return 0;
}

linkedlistheader.h:

class LinkedList
{
public:
// LinkedList constructor
LinkedList();
// ListNode struct --> Linked List
struct ListNode
{
    double value;
    ListNode *next;
    // Constructor
    ListNode(double value1, ListNode *next1 = nullptr)
    {
        value = value1;
        next = next1;
    }
};
// add(double) adds a node to the list with value x
void add(double x)
{
    if(head == nullptr)
    {
        head = new ListNode(x);
    }
    else
    {
        ListNode *nodePtr = head;
        while(nodePtr->next != nullptr)
        {
            nodePtr = nodePtr->next;
        }
        nodePtr->next = new ListNode(x);
    }
}
// isMember(x) trverses through list to determine if (value == x)
bool isMember(double x)
{
    ListNode *nodePtr = head;
    while(nodePtr->next != nullptr)
    {
        if (nodePtr->value != x)
        {
            return true;
        }
        else
            return false;
    }
    return false;
}
// displayList() prints out each member of the list (used to make sure add(double) was working properly)
void displayList()
{
    ListNode *nodePtr = head;
    while(nodePtr)
    {
        std::cout << nodePtr->value << " ";
        nodePtr = nodePtr->next;
    }
    std::cout << std::endl;
}
ListNode *head = nullptr;
};

这是我的日志中的完整错误

,因此错误很简单,您没有编写constortor LinkedList::LinkedList(),但您确实保证要编写它。

class LinkedList
{
public:
// LinkedList constructor
LinkedList();

您的代码中的链接列表构造函数在哪里?编写构造函数,或删除写信的承诺(我认为您可以做后者)。