-
Notifications
You must be signed in to change notification settings - Fork 30.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Explicit initialisation of Node-API addons #44853
Comments
You can export a function called There's also
Are you including tcc.h? It contains an |
Ah, I see NAPI_MODULE_INIT in the docs now, thanks (which seems to boil down to napi_register_module_v1). I am using the node.js v8.x node_api headers, which doesn't seem to have that macro. I needed to be able to use the official linux x86 nodejs binaries so I was using older headers. The following works for me (win32/linux x86) for >= v12.x (I assume v10.x will also work, but I didn't check):
For linux I just removed the
Nope I think the culprit is sys/cdefs.h (see tcc mailing list thread)
Thanks for your help, you can close off this ticket if you want. |
Glad to hear you found a working solution. Closing then. |
What is the problem this feature will solve?
I have been trying to build a Node-API module using the Tiny C Compiler (https://bellard.org/tcc/) . I've managed to do it (with a couple of work arounds) but I ran into some issues around the use of
__attribute__((constructor))
. Is there a reason this particular API design was chosen? Could an explicitly known init function be called if a module failed to self register?tcc has a couple of issues around the use of
__attribute__((constructor))
:__attribute__((constructor))
by tcc. I think this is a bug in the glibc headers, see https://lists.nongnu.org/archive/html/tinycc-devel/2022-10/msg00000.htmlTo work around this I used a newer version of tcc, and also had to expand out the NAPI_MODULE macro and move the
_register_...
declaration to the top of my source file: https://github.com/cosinusoidally/mishmashvm/blob/dev/tests/nodejs/stub.c (build script is https://github.com/cosinusoidally/mishmashvm/blob/dev/tests/nodejs/mk)Having an explicit init function could also be useful for compilers for other languages that potentially do not have support for constructors in shared libraries.
What is the feature you are proposing to solve the problem?
The ability to define an explicit init funtion to avoid the use of
__attribute__((constructor))
.What alternatives have you considered?
No response
The text was updated successfully, but these errors were encountered: