{"action":"opened","issue":{"url":"https://api.github.com/repos/facine/easyBlack/issues/4","labels_url":"https://api.github.com/repos/facine/easyBlack/issues/4/labels{/name}","comments_url":"https://api.github.com/repos/facine/easyBlack/issues/4/comments","events_url":"https://api.github.com/repos/facine/easyBlack/issues/4/events","html_url":"https://github.com/facine/easyBlack/issues/4","id":122630386,"number":4,"title":"static initialization problems... and suggested fix...","user":{"login":"supertwang","id":198209,"avatar_url":"https://avatars.githubusercontent.com/u/198209?v=3","gravatar_id":"","url":"https://api.github.com/users/supertwang","html_url":"https://github.com/supertwang","followers_url":"https://api.github.com/users/supertwang/followers","following_url":"https://api.github.com/users/supertwang/following{/other_user}","gists_url":"https://api.github.com/users/supertwang/gists{/gist_id}","starred_url":"https://api.github.com/users/supertwang/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/supertwang/subscriptions","organizations_url":"https://api.github.com/users/supertwang/orgs","repos_url":"https://api.github.com/users/supertwang/repos","events_url":"https://api.github.com/users/supertwang/events{/privacy}","received_events_url":"https://api.github.com/users/supertwang/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-12-16T23:50:14Z","updated_at":"2015-12-16T23:50:14Z","closed_at":null,"body":"Hi there,\r\n\r\nI am running into static initialization order issues with this library in its current form (aka the \"Static initialization order fiasco\" see: https://isocpp.org/wiki/faq/ctors#static-init-order ). \r\n\r\nI was able to fix it in my case by converting the following variables to the \"Construct On First Use Idiom\" (described just below the above link, on the same page): PIN_INDEX, BSPM_TEMPLATE and BSPWM_TEMPLATE.\r\n\r\nThe fix (which worked for me) is below, and won't affect the function of the library, just make it more portable/predictable across different compilers.  Essentially it just enforces a functional initialization order.\r\n\r\nIn the memGPIO.cpp:\r\n\r\nadd the following instead of the current static initialization of the above variables:\r\n\r\n    const std::map<std::string, const memGPIO::gpioPin> &memGPIO::PIN_INDEX() {\r\n      static const std::map<std::string, const memGPIO::gpioPin> *index = new std::map<std::string, const memGPIO::gpioPin>(memGPIO::initializePins());\r\n      return *index;\r\n    }\r\n    const std::string &memGPIO::BSPM_TEMPLATE()\r\n    {\r\n      static const std::string *tmpl = new std::string(memGPIO::initializeBSPMTemplate());\r\n      return *tmpl;\r\n    }\r\n    const std::string &memGPIO::BSPWM_TEMPLATE()\r\n    {\r\n      static const std::string *tmpl = new std::string( memGPIO::initializeBSPWMTemplate());\r\n      return *tmpl;\r\n    }\r\n\r\nIn memGPIO.hpp, replace the variable declarations with the following function declarations:\r\n\r\n      // Available PINs.\r\n      static const std::map <std::string, const gpioPin> &PIN_INDEX();\r\n\r\n      // DTS file templates.\r\n      static const std::string &BSPM_TEMPLATE();\r\n      static const std::string &BSPWM_TEMPLATE();\r\n\r\n\r\nFinally, in memGPIO.cpp, replace all uses of PIN_INDEX with PIN_INDEX(), BSPM_TEMPLATE with BSPM_TEMPLATE(), and PSPWM_TEMPLATE with PSPWM_TEMPLATE().\r\n\r\n\r\n"}}