Need help to resolve Linking Error : undefined reference on Linux with gcc/g++ compiler

Hi Team
%%%%%%%%%%%% I have a c++ file a.cpp which I use to create an archive (liba.a). Below is one method example

int someclass::methodA(input_variables)
{
Listiter<GfCalOvr> locListIter(prmOvrList);
// ...Some code here
return(success);
}


%%%%%%%%%%%%% In a header file which gets included, I have the below.



class Liztiter_ATTLC {
public:
~Liztiter_ATTLC();
// ... other members / variables / methods
}

template <class T> class Listiter;
template <class T> class Const_listiter;

template <class T> class Const_listiter : public Liztiter_ATTLC {
public:
~Const_listiter();
// ... other members / variables / methods
}


template <class T> class Listiter : public Const_listiter<T> {
public:
~Listiter();
//... other members / variables / methods
}


%%%%%%%%%%%%% The above archive (liba.a) gets successfully compiled and created. However, when this archive is linked
to a binary, it gives linking errors as below.

undefined reference to `Listiter<GfCalOvr>::~Listiter()'



%%%%%%%%%%%%% This code works fine from AIX with XLC compiler. However, when we move to Linux with gcc/g++, we get the above error.

Need help on how to resolve this error on Linux.
Is the Listiter destructor definitely defined?
Yes, We already defined Listiter destructor.
Is the Listiter destructor defined in the header file?
Last edited on
Yes we defined in header file also.
@OP,

Your post is very difficult to read with all of those "%%%%%%" lines.

Please post your code again and use code tags. Click the "Format:" button that looks like "<>", and paste your code between the generated tags. This will allow the indentation of your code to remain as well as line numbers that help us with comments.

You say that the destructors are defined in the header file, but you only show us the declarations. There is no destructor definition shown in your code. Despite your assurances to the contrary, it appears you never define your destructors, and that is why the linker error is encountered.

Please post the entire header files so we can see what you actually have and do not have defined. If this is too much code, strip out everything unnecessary, but leave enough that can be compiled and will still result in the problem. (Try to compile it to make sure)

Also, I don't think it's causing the problem, but since Liztiter_ATTLC is used as a base class, its destructor should be declared virtual.

Last edited on
provide a testcase that does reproduce your problem
- all necessary files (headers and cpps)
- all commands used to build

don't need to be your actual program, but it has to have the same relevant behaviour
Topic archived. No new replies allowed.