Undefined symbol
This is probably a really stupid question, but I'm about to flip out just trying to solve it. I have the following code:
(... indicates non-relevant code left out) in list.h (personal implementation of a linked list): class ListElement { ... }; class List { public: ... void *Remove(); // Take item off the front of the list void Remove(ListElement *); // Take the specified list element off the list ListElement* GetFirst(); // Getter function for first list element ... }; (in list.cc the corresponding functions are written) in threadtest.cc: #include "list.h" void test::BoardNext(){ List passengerList; passengerList.Remove(passengerList.GetFirst()); } I have a make file set up so that it compiles each of files first (which is fine) but then goes to run the following command: g++ ... list.o threadtest.o ... which generates the following error before exiting: Undefined first referenced symbol in file List::Remove(ListElement *) threadtest.o ld: fatal: Symbol referencing errors. No output written to nachos collect2: ld returned 1 exit status gmake[1]: Leaving directory `/home/hd03/m/mmorsi/nachos/os/code/threads' *** Error code 2 gmake[1]: *** [nachos] Error 1 make: Fatal error: Command failed for target `all' I'm about to tear my hair out here. Am I doing something wrong? I dont get errors for any of the other functions of List which I call in threadtest, just for the Remove(ListElement *) If someone could help me with this problem, I would be ever so gratefull. Thank you. |
Have you written the code for the function List::Remove(). I believe that is what the linker is looking for and not finding.
|
Solved
Thank you for your response graemef. It was a combination of two things:
1. In the header and source files I had overloaded the remove function as so: void *Remove(); // Take item off the front of the list void Remove(ListElement *); // Take the specified list element off the list What I had forgotten was that overloaded functions needed to return the same type. In one I was returning a void* in the other I was returning void. 2. In the source code I had neglected to include the 'List::' specifier infront of the overloaded remove function. Thus the compiler thought it was just some random function called remove and not the List::Remove function. After making these two changes, the code compiled fine. |
All times are GMT -5. The time now is 05:20 AM. |