I have files that are linked together:
basic.h
#pragma once
extern const string APPLICATION_NAME;
application.cpp
#include "basic.h"
const string APPLICATION_NAME = "MyApplication";
............
ErrorTables.h
class ErrorTable
{
public:
ErrorTable();
private:
map <index, errorRecord> _errorTable;
};
ErrorTables.cpp
#include "basic.h"
ErrorTable TheErrorTable;
ErrorTable::ErrorTable()
{
...
_errorTable[errorIndex] = errorRecord(APPLICATION_NAME + " hit some error.");
...
}
This code can be built and run OK in Visual Studio. When I use GCC, it can be build but failed in run time. The problem is in TheErrorTable that has static linkage and is created before main() is started; it can't resolve APPLICATION_NAME variable. If I hide it using local variable everything works OK.
Is there a GCC flag that force resolution of a static variable during build time or implements behavior of Visual Studio in some other way?