This is my first time writing a nodejs addon and been trying to make node-addon-api package work for hours but I dont get clang to find the napi header file thus i dont get autocompletion in vim and compiler throws a fatal error about it. I've followed node-addon-examples repo but nothing works.
In vim, when including the header file i get this message:
ā 3 #include <napi.h>
4 'napi.h' file not found
5 int main(in [clang: pp_file_not_found]
And compiler throws:
cc1: warning: /usr/include/node/node_api.h: not a directory
/home/prxvvy/workspace/a/source/main.c:3:10: fatal error: napi.h: No such file or directory
3 | #include <napi.h>
| ^~~~~~~~
However if I include the node_api header directly like this it does work because, as far as I know when installed nodejs the header files were installed in /usr/include/node but I feel like its not the best way to do the job.
3 #include <node/node_api.h>
4
My binding.gyp file is:
1 {
2 "targets": [
3 {
4 "target_name": "lib",
5 "cflags!": ["-fno-exceptions"],
6 "cflags_cc!": ["-fno-exceptions"],
7 "cflags": ["-Wall", "-Wno-psabi", "-std=c++14", "-pthread"],
8 "cflags_cc": ["-Wall", "-Wno-psabi", "-pthread"],
9 "sources": ["./source/lib.c", "./source/lib.h", "./source/main.c"],
10 "include_dirs": [
11 "<!(node -p \"require('node-addon-api').include_dir\")",
12 "../node_modules/node-addon-api",
13 "node_modules/node-addon-api",
14 "/usr/include/node",
15 "/usr/local/include/node",
16 ],
17 "dependencies": ["<!(node -p \"require('node-addon-api').gyp\")"],
18 "defines": ["NAPI_CPP_EXCEPTIONS"],
19 }
20 ]
21 }
~
I'd like to get some help if im missing something to do