I seem to always get this error when I start a new assignment, and I never remember how I fixed it the last time. This time it's driving me bat s- crazy. I've been googling for a few hours now with no luck so I've decided it's time to post for help and go to bed.
Here's some snippets of the code first:
LinkedList.h:
#include "ListNode.h"
#include <string>
using std::string;
#ifndef LINKEDLIST_H_
#define LINKEDLIST_H_
template <class T>
class LinkedList
{
public:
LinkedList();
virtual ~LinkedList();
T push(T);
T get(int position);
T remove(int position);
ListNode<T>* getNode(int position);
ListNode<T>* lastNode();
string toString();
private:
ListNode<T> *firstNode;
int length;
};
#endif /*LINKEDLIST_H_*/
LinkedList.cpp: (the first few lines of it anyway -- all of the functions declared in the .h are implemented below the empty constructor/destructor)
/tmp/ccnecGST.o: In function `main':
Main.cpp:(.text+0xaf): undefined reference to `LinkedList<int>::LinkedList()'
Main.cpp:(.text+0xc2): undefined reference to `LinkedList<int>::push(int)'
Main.cpp:(.text+0xcd): undefined reference to `LinkedList<int>::~LinkedList()'
Main.cpp:(.text+0xe8): undefined reference to `LinkedList<int>::~LinkedList()'
collect2: ld returned 1 exit status
I can't figure it out. I'm really hoping it's just something really simple that I've missed over and over again, but who knows.
Question
smiddy
I seem to always get this error when I start a new assignment, and I never remember how I fixed it the last time. This time it's driving me bat s- crazy. I've been googling for a few hours now with no luck so I've decided it's time to post for help and go to bed.
Here's some snippets of the code first:
LinkedList.h:
LinkedList.cpp: (the first few lines of it anyway -- all of the functions declared in the .h are implemented below the empty constructor/destructor)
Main.cpp:
So that's the effective source, now here's what's being run to compile:
Which gives me this error:
I can't figure it out. I'm really hoping it's just something really simple that I've missed over and over again, but who knows.
Thanks very much for the help.
Link to comment
https://www.neowin.net/forum/topic/633585-c-undefined-reference-to/Share on other sites
6 answers to this question
Recommended Posts