In an already existing and fairly large project, I enable gcc compiler optimization O1.
Without this option, everything builds, binds and works fine. with the option turned on, the main executable compilations and links, but I get linker errors when linking one of the unit tests.
Between these two compilation runs, I did not change either the code or the files, but only the optimization flag O1.
The error I get is:
Configuration.a(Builder.o): In function `Builder::Create() const':
Builder.cpp:123: undefined reference to `Factory::Instance()'
Somewhere during the binding process, he encounters this line (line 123) Builder.cpp: cpp file
pObject = Factory::Instance()->CreateObject();
(Besides the function linker error Instance, I also get one of the function CreateObject)
When I look at Factory, I see: the header file
class Factory { public:
static Factory* Instance(); << rest of the file >>
And in the cpp file
Factory* Factory::sInstance = 0;
Factory* Factory::Instance() {
if (sInstance == 0)
{
sInstance = new Factory();
}
return sInstance; }
, .
nm Factory.o ( ) .
, , Factory::Instance(). - , , .
Google , -, .
- , ?