Global variable constructor ignored in nRF Connect

Check the below C++ code:

in file S.h, we define class S

class S {

public:
  S(char *name);
  void init();
};

in file S.cpp, we implement S constructor and function init()

#include "S.h"
#include "stdio.h"

S::S(char *name) {
    printf("S constructor\n");
}

void S::init() {
    printf("S init\n");
}

in file test.cpp we first declare a global variable m_s, and then call init()

#include "S.h"

S m_s("test");

void test() {
    m_s.init();
}

If we run the program under ncs 2.1.0 (i.e. call test() from main()), the constructor never run, while init() executes as expected.

We cannot even put a breakpoint in the constructor code, it is like the linker totaly ignored it.

The same code works fine in SES / SDK15.2 and other compilers.

Any ideas?

Thanks 

Related