delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/06/03/13:21:15

Newsgroups: comp.os.msdos.djgpp
From: Elliott Oti <e DOT oti AT stud DOT warande DOT ruu DOT nl>
Subject: Re: "Undefined resource" < What does it mean?
Sender: usenet AT fys DOT ruu DOT nl (News system Tijgertje)
Message-ID: <3393C596.6C54@stud.warande.ruu.nl>
Date: Tue, 3 Jun 1997 07:19:50 GMT
Reply-To: e DOT oti AT stud DOT warande DOT ruu DOT nl
References: <339045A8 DOT 7B00 AT geocities DOT com>
Mime-Version: 1.0
Organization: The Gauge Variance Promotion Society
Lines: 77
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Ali Bharmal wrote:
> 
> I attempted yesterday to link two object files together, one which holds
> the definition
> of members of a linked-list class (linkedlist.cc) and the other holding
> the main() function (bookmarks.cc). However, all member  functions which
> were not inlined in a header for the class and which were reference in
> bookmarks.cc caused the following type of error:
> 
> Compiling: bookmarks.cc
> no errors
> Compiling: linkedlist.cc
> no errors
> Creating: bookmarks.exe
> Error: bookmarks.o: In function `main':
> bookmarks.cc(201) Error: undefined reference
> to
> `LinkedList<bookmarkLine>::~LinkedList(void)
> There were some errors
> 
> What does "undefined reference" mean? The code for the linked list class
> is fine,
> there is a test main() function in linkedlist.cc which when built by
> itself tests the class and this work OK. What am I missing? I've tried
> to search for the error, but couldn't find anything useful?


The error message means the linker couldn't find the function definition
anywhere.
My guess is, if you're using templates, that the *template* itself is
defined, but no *functions* using the template were *defined* in the
header or in your own main.cc.

This sounds vague, I know, but what I mean is, the template definition
merely serves as a, er, template for your generalized linked-list
functions. Only when you actually supply an example function in your *.h
file, will the compiler generate code for that specific data-type. A
template != function definition, it serves as a *model* for future
definitions, and you have to define at least one function to get the
compiler to generate code for all your data types.

The solution would be to define a dummy function in your *.h file or a
*.cc file (which you link in first) that calls the template functions
with specific instanced linked-lists.

Kinda like this:

//----------------------------------------------------------------------
//File LinkedList.h
//Your function looks like this:

template <class foo>
void foo-fah(foo &f1,foo &f2)
{
 f2 = f1; 
}

//Add the ff. lines (or put 'em in a separate *.cc file, if you like)
//Calls foo-fah() with an instance of the data type LinkedList and
forces
//the compiler to generate a version of foo-fah()  for LinkedLists.

void dummy(LinkedList &L1, LinkedList &L2)
{
 foo-fah(L1,L2);
}
//----------------------------------------------------------------

Link all your *.o file together and it should work. 

Of course if that was not the problem, or you already thought of all
that, ignore the above blather. Or post more detailed info.
Good luck,

-- 
------------ Elliott Oti ---------------
   ------------- http://www.fys.ruu.nl/~oti  ---------

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019