Novice Linker Errors

G

GammaJoe

I'm relatively new to C++, and so when I ran across these linker
errors, I really didn't know how to fix them. I did a groups.google
search, and found plenty of issues with parameterized classes, or
using the wrong compiler, or a variety of other things that don't
apply to my problem. So, if anyone could help me out, that'd be
great.

DummyTester.cpp:
#include "DummyClass.h";
#include "CommunicatorImplementation.h";

int main(){
CommunicatorImplementation comm_imp;
Communicator * util = util_imp.Clone();
DummyClass dc(*util);
return 0;
}

When I run:
$g++ -I../src/ -I../../utils/src DummyTester.cpp

I get:
/tmp/ccxLnKku.o(.text+0x19): In function `main':
: undefined reference to
`CommunicatorImplementation::CommunicatorImplementation[in-charge]()'
/tmp/ccxLnKku.o(.text+0x3d): In function `main':
: undefined reference to
`DummyClass::DummyClass[in-charge](Communicator const&)'
/tmp/ccxLnKku.o(.text+0x4c): In function `main':
: undefined reference to
`CommunicatorImplementation::~CommunicatorImplementation
[in-charge]()'
/tmp/ccxLnKku.o(.text+0x63): In function `main':
: undefined reference to
`CommunicatorImplementation::~CommunicatorImplementation
[in-charge]()'
/tmp/ccxLnKku.o(.gnu.linkonce.t._ZNK17CommunicatorImplementation5CloneEv+0x24):
In function `CommunicatorImplementation::Clone() const':
: undefined reference to
`CommunicatorImplementation::CommunicatorImplementation[in-charge](CommunicatorImplementation
const&)'
collect2: ld returned 1 exit status

DummyClass, Communicator, and CommunicatorImplementation are
pre-established (and non-parameterized) modules and (in theory) should
not need any alteration. What do I need to change in my code or in
the way I run the compiler/linker that will make this program link?

Thanks in advance!

Joe
 
J

John Harrison

I'm relatively new to C++, and so when I ran across these linker
errors, I really didn't know how to fix them. I did a groups.google
search, and found plenty of issues with parameterized classes, or
using the wrong compiler, or a variety of other things that don't
apply to my problem. So, if anyone could help me out, that'd be
great.

DummyTester.cpp:
#include "DummyClass.h";
#include "CommunicatorImplementation.h";
int main(){
CommunicatorImplementation comm_imp;
Communicator * util = util_imp.Clone();
DummyClass dc(*util);
return 0;
}

When I run:
$g++ -I../src/ -I../../utils/src DummyTester.cpp

I get:
/tmp/ccxLnKku.o(.text+0x19): In function `main':
: undefined reference to
`CommunicatorImplementation::CommunicatorImplementation[in-charge]()'
/tmp/ccxLnKku.o(.text+0x3d): In function `main':
: undefined reference to
`DummyClass::DummyClass[in-charge](Communicator const&)'
/tmp/ccxLnKku.o(.text+0x4c): In function `main':
: undefined reference to
`CommunicatorImplementation::~CommunicatorImplementation
[in-charge]()'
/tmp/ccxLnKku.o(.text+0x63): In function `main':
: undefined reference to
`CommunicatorImplementation::~CommunicatorImplementation
[in-charge]()'
/tmp/ccxLnKku.o(.gnu.linkonce.t._ZNK17CommunicatorImplementation5CloneEv+0x24):
In function `CommunicatorImplementation::Clone() const':
: undefined reference to
`CommunicatorImplementation::CommunicatorImplementation[in-charge](CommunicatorImplementation
const&)'
collect2: ld returned 1 exit status

DummyClass, Communicator, and CommunicatorImplementation are
pre-established (and non-parameterized) modules and (in theory) should
not need any alteration. What do I need to change in my code or in
the way I run the compiler/linker that will make this program link?

Thanks in advance!

Joe

You need to link with the actual code that implements what is declared in
the header files. Header file on their own are not normally sufficient.

Do you have a CommunicatorImplementation.cpp or
CommunicatorImplementation.cc file?

john
 
A

AVR

John said:
I'm relatively new to C++, and so when I ran across these linker
errors, I really didn't know how to fix them. I did a groups.google
search, and found plenty of issues with parameterized classes, or
using the wrong compiler, or a variety of other things that don't
apply to my problem. So, if anyone could help me out, that'd be
great.

DummyTester.cpp:
#include "DummyClass.h";
#include "CommunicatorImplementation.h";
int main(){
CommunicatorImplementation comm_imp;
Communicator * util = util_imp.Clone();
DummyClass dc(*util);
return 0;
}

When I run:
$g++ -I../src/ -I../../utils/src DummyTester.cpp

I get:
/tmp/ccxLnKku.o(.text+0x19): In function `main':
: undefined reference to
`CommunicatorImplementation::CommunicatorImplementation[in-charge]()'
/tmp/ccxLnKku.o(.text+0x3d): In function `main':
: undefined reference to
`DummyClass::DummyClass[in-charge](Communicator const&)'
/tmp/ccxLnKku.o(.text+0x4c): In function `main':
: undefined reference to
`CommunicatorImplementation::~CommunicatorImplementation
[in-charge]()'
/tmp/ccxLnKku.o(.text+0x63): In function `main':
: undefined reference to
`CommunicatorImplementation::~CommunicatorImplementation
[in-charge]()'
/tmp/ccxLnKku.o(.gnu.linkonce.t._ZNK17CommunicatorImplementation5CloneEv+0x24):

In function `CommunicatorImplementation::Clone() const':
: undefined reference to
`CommunicatorImplementation::CommunicatorImplementation[in-charge](CommunicatorImplementation

const&)'
collect2: ld returned 1 exit status

DummyClass, Communicator, and CommunicatorImplementation are
pre-established (and non-parameterized) modules and (in theory) should
not need any alteration. What do I need to change in my code or in
the way I run the compiler/linker that will make this program link?

Thanks in advance!

Joe


You need to link with the actual code that implements what is declared
in the header files. Header file on their own are not normally sufficient.

Do you have a CommunicatorImplementation.cpp or
CommunicatorImplementation.cc file?

john

I'm pretty new myself, but I've chewed over this one before.
You could either include the all the .cpp files in your compile command as :
$g++ -I../src/ -I../../utils/src DummyTester.cpp \
<whatever>/CommunicatorImplementation.cpp <whatever>/DummyClass.cpp

Or you could compile the .cpp files without linking them using the -c
flag of g++ as:

$g++ -I../src/ -I../../utils/src -c \
<whatever>/CommunicatorImplementation.cpp -o \
CommunicatorImplementation.o

//similarly for DummyClass

and finally link all these along with the driver file as:

$g++ -I../src/ -I../../utils/src -c \
DummyTester.cpp CommunicatorImplementation.o ...

This is the approach used in makefiles.

HTH,
--AVR
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,899
Latest member
RodneyMcAu

Latest Threads

Top