I have files that are related:
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 created and run OK in Visual Studio. When I use GCC, it can be created but not executed at runtime. The problem is with TheErrorTable, which has a static link and created before main () was run; it cannot resolve the variable APPLICATION_NAME. If I hide it with a local variable, everything works fine.
Is there a GCC flag that forcibly resolves a static variable at build time or implements Visual Studio behavior in some other way?
source share