Dear Community,
I have a Problem to get access to a extern Variable.
This is my Situation:
I'm defined a vector about a self written class:
#ifndef Data
#define Data
...
typedef std::vector<TrackParamDat> TPDataTy;
#endif
extern TPDataTy TPData;
A would build the Object like:
TPData = TPDataTy();
But when ever I try this, I get a Error Message like this:
/usr/bin/ld: /tmp/ccsgNs1i.o: in function `MyFrame::MyFrame(wxString const&, wxPoint const&, wxSize const&)':
test.cpp:(.text+0x5b9): undefined reference to `TPData'
/usr/bin/ld: /tmp/ccDZ4gpU.o: in function `TrackControl::TrackControl(wxPanel*, int)':
TrackControl.cpp:(.text+0x9e0): undefined reference to `TPData'
/usr/bin/ld: TrackControl.cpp:(.text+0xa1a): undefined reference to `TPData'
collect2: error: ld returned 1 exit status
Declaring a variable as extern does not allocate space for it.
You still have to declare the variable in exactly one translation unit.
e.g. TPDataTy TPData;
Ok,
but:
1. It is allowed to make a vector / this vector extern
2. It is correct to define "extern TPDataTy TPData" in the header File.
3. I should only give in one .cpp File the Command "TPDataTy TPData = TPDataTy();"
Oh dear,
I'm too rubbisch.
The difficult things are all clear to this point.
But the simplest thing you can imagine are my fatal error.
I must define the variable once in a *.cpp File but out of any method, and not in main().
So pleace hunt me not to hell ... but I'm so stuppid.