Given the following code:
// foo.h
#ifdef BIG_DATA_MACRO
#warning "TEXT ADDED"
#define TEXT_HANDLING_MACRO \
static const char * TEXT[]; \
static const char * getText( int _enum ) { \
return TEXT[_enum]; \
}
#else
#warning "TEXT NOT ADDED"
#define TEXT_HANDLING_MACRO
#endif
struct Foo {
TEXT_HANDLING_MACRO
};
// foo.cpp
#include "foo.h"
#ifdef BIG_DATA_MACRO
const char * Foo::TEXT[] = {
"ONE",
"TWO",
"THREE",
0
};
#endif
// other_file.cpp
#include <iostream>
#define BIG_DATA_MACRO
#include "foo.h"
void bar() {
std::cout << Foo::TEXT[0] <<std::endl;
}
The warning TEXT ADDED
appears everywhere, but TEXT NOT ADDED
appears for moc_other_file.cpp
. How can we fix this bug.
The compilation output is:
/foo.h:15: warning: #warning "TEXT NOT ADDED" [-Wcpp] Debug/moc_other_file.cpp:9: from moc_otherfile.cpp:9:
other_file.cpp:26: error: undefined reference to 'Foo::TEXT'