Node-addon-api: "expected initializer before InitAll"

Created on 17 Apr 2019  Â·  2Comments  Â·  Source: nodejs/node-addon-api

I am working through the object wrap example in node-addon-examples. I have the following code:

Napi::Object InitAll(Napi::Env env, Napi::Object exports)
{
    return Connection::Init(env, exports);
}

NODE_API_MODULE(xcb, InitAll)

The compiler does not seem to like it though:

../lib/main.cc:4:14: error: expected initializer before ‘InitAll’
 Napi::Object InitAll(Napi::Env env, Napi::Object exports)
              ^~~~~~~
In file included from /mnt/c/node-xcb/node_modules/node-addon-api/napi.h:1839:0,
                 from ../lib/main.cc:1:
../lib/main.cc: In function ‘napi_value__* __napi_InitAll(napi_env, napi_value)’:
../lib/main.cc:9:22: error: ‘InitAll’ was not declared in this scope
 NODE_API_MODULE(xcb, InitAll)
                      ^

Most helpful comment

Nevermind. Turns out I was missing a semicolon at the end of a header file.
The compiler failed to pick it up, oddly enough.

All 2 comments

Hi @arutr,
does the original example work? Which version of Node.js are you using? Could you post your code or a stub of it or if it's public maybe you ca post the link.
Could you try to change:
NODE_API_MODULE(xcb, InitAll) to NODE_API_MODULE(NODE_GYP_MODULE_NAME, InitAll)?
keep me updated about this.

Nevermind. Turns out I was missing a semicolon at the end of a header file.
The compiler failed to pick it up, oddly enough.

Was this page helpful?
0 / 5 - 0 ratings