undefined reference to 'function'

I write a brief code to call an exist class and always was told "undefined reference to `T::T(char*)' and undefined reference to `T::~T()'...

The main function is :

Int_t main(Int_t argc,char** argv)
{
if(argc !=3) {
std::cerr << "Argument error." << std::endl;
return 1;
}
char* ifname = argv[1];
char* ofname = argv[2];
TFile* in = new TFile(ifname);
T tloop(ifname);
TTree* tro = (TTree *) gDirectory->Get("T");

return 0;
}

T class is declared in T.h and implemented in T.C. I'm pretty sure that T.h has been linked correctly.

In T.h
class T {
public :
T(char* Filename);
....

In T.C
T::T(char* Filename)
{
....
}

Does anybody know why I can't compile the code correctly?

Thanks.
Last edited on
Did you mean T.c is being linked correctly? That's what you should be linking, but I'm not sure if it's a typo or actually the issue. Are you using an IDE or compiling on the command line yourself? If it's the latter, how are you doing it? And did you implement the destructor for T?
Hi,

Thanks for your prompt reply.

1. T.h is included at the beginning of the main code ( #include "src/T.h")

2. I merged the compile commands in Makefile. The Makefile written in this way:

MAINS = ana
PACKAGE = $(shell basename `pwd`)
INSTALL_LIBS = no
INSTALL_BINS = yes

include $(CONFIG_DIR)/Makefile.bin

3. The destructor for T is implemented in T.h:
T::~T()
{
if (!fChain) return;
delete fChain->GetCurrentFile();
}

But I still can't find what's wrong....
1. ¿You put your headers inside a src/ directory? Weird.
2. ¿And the compilation command?

¿Is there a good reason for using dynamic allocation? TFile in(ifname);
Hi ne555,

Thanks for your further questions and remind me something...

1. Yes, I put T.C and T.h in the src/ directory. Both of them are automatically generated by another software(root). Anyway, I have moved T.h to the relative include/ directory and got same compile error message...

2. The compilation commands are a little complex since it links several other Makefile... I'll study the detail information in each Makefile.

As to the dynamic allocation, I've to do it in this way since there are a bunch of these files to run in this code...
AFAIK if both files are in the same directory, you should simply #include "T.h"
it will not change if you are compiling from outside the path.


As to the dynamic allocation, I've to do it in this way since there are a bunch of these files to run in this code...
It may be if you need a collection, and that class does not have a copy constructor...


As for the makefiles, show the steps
$ make --just-print
Thanks ne555.

I found it's because the name of T.C ...

The Makefile only compile the files with .cc but not .C

It can be compiled correctly once I changed T.C to T.cc

Thanks all of you!
Last edited on
Topic archived. No new replies allowed.