Xpcom strings

Hi all,

I work on xpcom component for Firefox 52esr, and I’m stuck on xpcom strings. Code below demonstrates the same problem which I have in component:

#include "mozilla-config.h"
#include "nsStringAPI.h"
#include <iostream>

using namespace std;

int main() {
        NS_NAMED_LITERAL_STRING(str, "test");
        cout << str.Length() << endl;
        cout << str.CharAt(0) << endl;
}

Line with Length() outputs 0, and segmentation fault happens on line with CharAt. So, obviously, for whatever reason string was not initialized properly. Why and how to fix it? Does anybody know?