Linker problems with g++

Linker problems with g++

Post by Steffen Koehl » Tue, 09 Nov 1999 04:00:00



Hello,

I have an project with an abstract class ca_field and two
implementations of this class (ca_grid and ca_planar). No error occurs
when I compile the project, but the linker says:

ca_grid.o: In function `ca_grid type_info function':
ca_grid.o(.text+0x270d): undefined reference to `ca_field type_info
function'
ca_grid.o(.text+0x2714): undefined reference to `ca_field type_info
node'
ca_grid.o: In function `ca_field::ca_field(void)':
ca_grid.o(.ca_field::gnu.linkonce.t.(void)+0x8): undefined reference
to `ca_field virtual table'
ca_planar.o: In function `ca_planar type_info function':
ca_planar.o(.text+0x212d): undefined reference to `ca_field type_info
function'
ca_planar.o(.text+0x2134): undefined reference to `ca_field type_info
node'
GNU ld version 2.9.1 (with BFD 2.9.1.0.15)
  Supported emulations:
  elf_i386
  i386linux
collect2: ld returned 1 exit status

I'am using
gcc version egcs-2.91.60 19981201 (egcs-1.1.1 release)

Whats the problem ?

thanks
Steffen

 
 
 

Linker problems with g++

Post by Ed Holloma » Tue, 09 Nov 1999 04:00:00




> Hello,

> I have an project with an abstract class ca_field and two
> implementations of this class (ca_grid and ca_planar). No error occurs
> when I compile the project, but the linker says:

> ca_grid.o: In function `ca_grid type_info function':
> ca_grid.o(.text+0x270d): undefined reference to `ca_field type_info
> function'
> ca_grid.o(.text+0x2714): undefined reference to `ca_field type_info
> node'
> ca_grid.o: In function `ca_field::ca_field(void)':
> ca_grid.o(.ca_field::gnu.linkonce.t.(void)+0x8): undefined reference
> to `ca_field virtual table'
> ca_planar.o: In function `ca_planar type_info function':
> ca_planar.o(.text+0x212d): undefined reference to `ca_field type_info
> function'
> ca_planar.o(.text+0x2134): undefined reference to `ca_field type_info
> node'
> GNU ld version 2.9.1 (with BFD 2.9.1.0.15)
>   Supported emulations:
>   elf_i386
>   i386linux
> collect2: ld returned 1 exit status

> I'am using
> gcc version egcs-2.91.60 19981201 (egcs-1.1.1 release)

> Whats the problem ?

> thanks
> Steffen

Sounds like your inherited classes (ca_grid and ca_planar) don't know
about the base class ca_field.  Do you have a #include to the base
class definition/member functions in your inherited class definition
files?  Something like:

  File with ca_grid class definition:
   #include "ca_field.h"

     class ca_planar : public ca_field
     { // stuff };

Regards,

Ed Holloman

 
 
 

Linker problems with g++

Post by Steffen Koehl » Wed, 10 Nov 1999 04:00:00


: Sounds like your inherited classes (ca_grid and ca_planar) don't know
: about the base class ca_field.  Do you have a #include to the base
: class definition/member functions in your inherited class definition
: files?  Something like:
:
:   File with ca_grid class definition:
:    #include "ca_field.h"
:
:      class ca_planar : public ca_field
:      { // stuff };
:
: Regards,
:
: Ed Holloman
Thanks,

but I have included the base class :-( Some background informations: The
project is written in C and only this three classes are C++.

bye Steffen

 
 
 

Linker problems with g++

Post by QuestionExchang » Fri, 19 Nov 1999 04:00:00


Quote:> Hello,

> I have an project with an abstract class ca_field and two
> implementations of this class (ca_grid and ca_planar). No
error occurs
> when I compile the project, but the linker says:

> ca_grid.o(.ca_field::gnu.linkonce.t.(void)+0x8): undefined
reference
> to `ca_field virtual table'

Please attach some of your code next time you post.
The above error may be because you have forgotten to
declare a virtual destructor (even if it's a do nothing
dtor) in the abstract base class. Check all your declarations
for missing virtual modifiers - without these the virtual
table may be missing or incomplete.
Joseph

--
  This answer is courtesy of QuestionExchange.com
  http://www.questionexchange.com/showUsenetGuest.jhtml?ans_id=7719&cus...

 
 
 

Linker problems with g++

Post by Steffen Koehl » Sat, 20 Nov 1999 04:00:00


: > to `ca_field virtual table'
: Please attach some of your code next time you post.
At the time I have found this error, the code was to big and can't
construct an simple example.
Now I have found the error, an forgotten =0 in my abstract class :-(
Is there an tool which find this error?

bye Steffen
: The above error may be because you have forgotten to
: declare a virtual destructor (even if it's a do nothing
: dtor) in the abstract base class. Check all your declarations
: for missing virtual modifiers - without these the virtual
: table may be missing or incomplete.
: Joseph
:
: --
:   This answer is courtesy of QuestionExchange.com
:   http://www.questionexchange.com/showUsenetGuest.jhtml?ans_id=7719&cus...

 
 
 

1. Problem with templates (apparently a linker problem)

{ Would someone be willing to draft an FAQ around this topic? -vdv }

I'm running into trouble in defining a class template for create
dynamic bidimensional arrays.

I want to define an array of whatever data type (that's why I'm
trying to use a class template), but I have a message of unresolved
names (with the g++ compiler) when I try to define an object which
is a bidimensional array of ints.

Maybe I'm just missing some switch in the command line?  (like, say,
when you use any math function and you forget to put the -lm switch
at the end?).  I checked the man pages and the FAQ, but found no
clues to help me solve the problem.

Any help will be highly appreciated!  (BTW, if possible, reply by
e-mail - or at least send me a Carbon-Copy, if you decide to post
a reply).  I'm including the code at the bottom of the message.

Thanks a lot!

Carlos
--

In file ARRAYS.H:

template<class DT>
class dynamic_array
{
public:
    dynamic_array ();
    dynamic_array (int, int);
    ~dynamic_array ();
    DT & operator() (int, int);
//    void redim (int, int, int = 0);   Not implemented yet
//    void ubound (int);                Not implemented yet
private:
    DT ** data;
    int size_subscript_1;
    int size_subscript_2;

In file ARRAYS.C++:

#include "arrays.h"

template<class DT>
dynamic_array<DT>::dynamic_array ()
{
    cerr << "Error: Must specify dynamic array size!" << endl << endl;
    exit (1);

template<class DT>

dynamic_array<DT>::dynamic_array (int size1, int size2)
{
    data = new DT * [size2];

    .....  (the rest of the code ommited)

In file TEST.C++:

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

main ()
{
    dynamic_array<int> array;     /* Should invoke the default constructor
                                   and print an error message */

    //  .....

    cout << "I worked!" << endl;

(this simple program should print an error message and quit;  though,
it does not compile...  :-( ...)


      [ about comp.lang.c++.moderated. First time posters: do this! ]

2. NFSS2: nfeuler.sty + cm-fonts ...

3. C++ kernel linker problems - help please!

4. Warp Server Beta?

5. Watcom linker problem

6. Nick's web/ftp site down?

7. Perplexing problem with Unresolved external symbol linker errors

8. Clarification on recent NYT article

9. /OPT:REF linker problem with MSVC++

10. linker problems with 2 part source?

11. Linker Problems using OWL

12. Help! BC++/OWL Linker problem.

13. Q.Linker problems