Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7908519
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T11:59:05+00:00 2026-06-03T11:59:05+00:00

I’m working on an assignment to implement insertions into an AVL tree, and I’m

  • 0

I’m working on an assignment to implement insertions into an AVL tree, and I’m getting three “Apple Mach-O Linker (ld)” errors. My limited understanding of these errors is that they come up when a something is referenced from a library that is not properly included in the project. Here are is the error message Xcode is giving me:

Ld /Users/gusmurphy/Library/Developer/Xcode/DerivedData/AVLInsertion-eylpvolyxvuwbygcvocqhleyvzcv/Build/Products/Debug/AVLInsertion normal x86_64
cd /Users/gusmurphy/Documents/CMSC270/AVLInsertion
setenv MACOSX_DEPLOYMENT_TARGET 10.6
/Developer/usr/bin/clang++ -arch x86_64 -isysroot /Developer/SDKs/MacOSX10.6.sdk -L/Users/gusmurphy/Library/Developer/Xcode/DerivedData/AVLInsertion-eylpvolyxvuwbygcvocqhleyvzcv/Build/Products/Debug -F/Users/gusmurphy/Library/Developer/Xcode/DerivedData/AVLInsertion-eylpvolyxvuwbygcvocqhleyvzcv/Build/Products/Debug -filelist /Users/gusmurphy/Library/Developer/Xcode/DerivedData/AVLInsertion-eylpvolyxvuwbygcvocqhleyvzcv/Build/Intermediates/AVLInsertion.build/Debug/AVLInsertion.build/Objects-normal/x86_64/AVLInsertion.LinkFileList -mmacosx-version-min=10.6 -o /Users/gusmurphy/Library/Developer/Xcode/DerivedData/AVLInsertion-eylpvolyxvuwbygcvocqhleyvzcv/Build/Products/Debug/AVLInsertion

Undefined symbols for architecture x86_64:
"AVLTree<int>::insert(int const&)", referenced from:
  _main in main.o
"AVLTree<int>::snapShot(std::ostream&, AVLNode<int>*)", referenced from:
  AVLTree<int>::snapShot(std::ostream&) in main.o
"AVLTree<int>::clear(AVLNode<int>*)", referenced from:
  AVLTree<int>::clear() in main.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Here is “main.cpp”:

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

int main (int argc, const char * argv[])
{
cout << "Enter an integer to be insterted: " << endl;
int i;
AVLTree<int> tree;
while (true) {
    scanf("%d", &i);
    tree.insert(i);
    tree.snapShot(cout);
    }
}

One thing that I’m especially curious about is why one of the errors has to do with AVLTree<int>::clear(AVLNode<int>*), even though it isn’t called anywhere explicitly (as far as I can tell). I’ll also put the header and implementation files for the AVLTree up here.

Here is “AVLTree.h”:

#include <iostream>

using namespace std;

#ifndef AVL_TREE
#define AVL_TREE

template<class T>
class AVLNode {
public:
    AVLNode() { 
        left = right = 0; 
    }
    AVLNode(const T& el, AVLNode *l = 0, AVLNode *r = 0, int b = 0) {
        key = el; left = l; right = r; balance = b;
    }
    T key;
    AVLNode *left, *right;
    int balance;
};

template<class T>
class AVLTree {
public:
    AVLTree() { 
        root = 0; 
    }
    ~AVLTree() { 
        clear();
    }
    void clear() {
        clear(root); root = 0;
    }
    bool isEmpty() const { 
        return root == 0; 
    }
    void snapShot(ostream& out) {
        out << "TreeForm[";
        snapShot(out,root);
        out << ']' << endl;
    }
    void preorder() { 
        preorder(root);  
    }
    void inorder() { 
        inorder(root); 
    }
    void postorder() { 
        postorder(root); 
    }
    void insert(const T&);
    T* search(const T& el) const { 
        return search(root,el);
    }
protected:
    AVLNode<T>* root;
    void clear(AVLNode<T>*);
    T* search(AVLTree<T>* p, const T& el) const;
    void preorder(AVLNode<T>*);
    void inorder(AVLNode<T>*);
    void postorder(AVLNode<T>*);
    void snapShot(ostream& out,AVLNode<T> *p);
    void visit(AVLNode<T>* p) { 
        cout << p->key << ' '; 
    }
    void rightRotation(AVLNode<T>* &node) {
        AVLNode<T>* left = node->left;

        node->left = left->right;
        left->right = node;
        node = left;
    }
    void leftRotation(AVLNode<T>* &node) {
        AVLNode<T>* right = node->right;

        node->right = right->left;
        right->left = node;
        node = right;
    }
};

#endif

And “AVLTree.cpp”:

#include "AVLTree.h"
#include <iostream>

template<class T>
void AVLTree<T>::clear(AVLNode<T> *p) {
    if (p != 0) {
        clear(p->left);
        clear(p->right);
        delete p;
    }
}

template<class T>
void AVLTree<T>::insert(const T& el) {  
    if (root == 0) {
        root = new AVLNode<T>(el);
        return;
    }

    AVLNode<T>* parent = 0;
    AVLNode<T>** tmp = root;
    AVLNode<T>* ancestor = 0;

    while (tmp != 0) {
        parent = *tmp;
        if (ancestor == 0 && (parent->balance == 1 || parent->balance == -1))
            ancestor = parent;
        // "ancestor" will point to the first node with an unnacceptable balance, if there is one.
        if (el >= parent) {
            tmp = parent->right;
            parent->balance++;
        } else {
            tmp = parent->left;
            parent->balance--;
        }
    };
    tmp = new AVLNode<T>(el);

    if (ancestor != 0) {
        if (ancestor->balance != 0) {
            if (el >= ancestor->key) {
                if (el >= parent) {
                    rightRotation(ancestor);
                } else {
                    rightRotation(parent);
                    rightRotation(ancestor);
                }
            } else {
                if (el < parent) {
                    leftRotation(ancestor);
                } else {
                    leftRotation(parent);
                    leftRotation(ancestor);
                }
            }
        }
    }
}

template<class T>
T* AVLTree<T>::search(AVLTree<T>* p, const T& el) const {
    while (p != 0)
        if (el == p->key)
            return &p->key;
        else if (el < p->key)
            p = p->left;
        else p = p->right;
    return 0;
}

template<class T>
void AVLTree<T>::inorder(AVLNode<T> *p) {
    if (p != 0) {
        inorder(p->left);
        visit(p);
        inorder(p->right);
    }
}

template<class T>
void AVLTree<T>::preorder(AVLNode<T> *p) {
    if (p != 0) {
        visit(p);
        preorder(p->left);
        preorder(p->right);
    }
}

template<class T>
void AVLTree<T>::postorder(AVLNode<T>* p) {
    if (p != 0) {
        postorder(p->left);
        postorder(p->right);
        visit(p);
    }
}

template <class T>
void AVLTree<T>::snapShot(ostream& out, AVLNode<T> *p)
{
    out << '\"' << p->key << '\"';
    if(p->left != 0 || p->right != 0) {
        out << '[';
        if(p->left==0)
            out << "\"\"";
        else
            snapShot(out,p->left);
        out << ',';
        if(p->right==0)
            out << "\"\"";
        else
            snapShot(out,p->right);
        out << ']';
    }
}

Thank you very much for your time! And I’m sorry to create another thread about this error message, but I wasn’t able to put much together about my instance of the problem from what I found.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T11:59:08+00:00Added an answer on June 3, 2026 at 11:59 am

    Templated classes definition must be available in the header file. You can read about this here.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I am currently running into a problem where an element is coming back from
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.