LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 02-12-2006, 03:55 PM   #1
movitto
Member
 
Registered: May 2004
Distribution: Fedora 4 and Slackware
Posts: 179

Rep: Reputation: 30
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.
 
Old 02-12-2006, 04:09 PM   #2
graemef
Senior Member
 
Registered: Nov 2005
Location: Hanoi
Distribution: Fedora 13, Ubuntu 10.04
Posts: 2,379

Rep: Reputation: 148Reputation: 148
Have you written the code for the function List::Remove(). I believe that is what the linker is looking for and not finding.
 
Old 02-18-2006, 01:11 AM   #3
movitto
Member
 
Registered: May 2004
Distribution: Fedora 4 and Slackware
Posts: 179

Original Poster
Rep: Reputation: 30
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.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Undefined symbol __pure_virtual anand_mirasdar Programming 1 08-11-2005 02:20 PM
snort failed: snort: symbol lookup error: undefined symbol: usmAES192PrivProtocol Emmanuel_uk Linux - Security 1 07-10-2005 10:29 AM
undefined symbol: X509_free irutgers Linux - Security 2 03-03-2005 07:15 PM
undefined symbol: _ZN13QWindowsStyleC1Ev r_jensen11 Linux - Software 1 09-10-2004 06:23 AM
undefined symbol _ZN11KMainWindow4showEv danahata Slackware 0 02-25-2004 12:50 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:07 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration