-
Notifications
You must be signed in to change notification settings - Fork 181
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
how does NODE_STATIC_LIBRARY work ? #9
Comments
Hi @tommyZZM , It was supposed to remove the static attribute so we assure the
The Since you're trying to use static libraries in your build system, you need to make sure that: Hope this is helpful. |
Thankyou! Following your tips i embed node.js as static library successfully already~. Those Then, once those bulitin module functions was referenced in the main code, those functions will run automatily as usual. There are few points should be notice:
i use header file below to do so. #ifndef ref_node_modules_builtin
#define ref_node_modules_builtin
#include <node.h>
extern "C" {
void _register_async_wrap(void);
void _register_cares_wrap(void);
void _register_fs_event_wrap(void);
void _register_js_stream(void);
void _register_buffer(void);
void _register_contextify(void);
void _register_crypto(void);
void _register_fs(void);
void _register_http_parser(void);
void _register_os(void);
void _register_util(void);
void _register_v8(void);
void _register_zlib(void);
void _register_pipe_wrap(void);
void _register_process_wrap(void);
void _register_signal_wrap(void);
void _register_spawn_sync(void);
void _register_stream_wrap(void);
void _register_tcp_wrap(void);
void _register_timer_wrap(void);
void _register_tls_wrap(void);
void _register_tty_wrap(void);
void _register_udp_wrap(void);
void _register_uv(void);
void _register_config(void);
void _register_url(void);
void _register_module_wrap(void);
}
static void (*_place_holder_builtin_modules)();
void _ref_node_modules_builtin(void) __attribute__((constructor)) {
// assign register functions in a never used variable
// so thattell linker to recognize the default caller in libnode.a
_place_holder_builtin_modules = _register_async_wrap;
_place_holder_builtin_modules = _register_cares_wrap;
_place_holder_builtin_modules = _register_fs_event_wrap;
_place_holder_builtin_modules = _register_js_stream;
_place_holder_builtin_modules = _register_contextify;
_place_holder_builtin_modules = _register_crypto;
_place_holder_builtin_modules = _register_fs;
_place_holder_builtin_modules = _register_http_parser;
_place_holder_builtin_modules = _register_os;
_place_holder_builtin_modules = _register_util;
_place_holder_builtin_modules = _register_v8;
_place_holder_builtin_modules = _register_zlib;
_place_holder_builtin_modules = _register_pipe_wrap;
_place_holder_builtin_modules = _register_process_wrap;
_place_holder_builtin_modules = _register_signal_wrap;
_place_holder_builtin_modules = _register_spawn_sync;
_place_holder_builtin_modules = _register_stream_wrap;
_place_holder_builtin_modules = _register_tcp_wrap;
_place_holder_builtin_modules = _register_timer_wrap;
_place_holder_builtin_modules = _register_tls_wrap;
_place_holder_builtin_modules = _register_tty_wrap;
_place_holder_builtin_modules = _register_udp_wrap;
_place_holder_builtin_modules = _register_uv;
_place_holder_builtin_modules = _register_config;
_place_holder_builtin_modules = _register_url;
_place_holder_builtin_modules = _register_module_wrap;
}
#endif /* ref_node_modules_builtin */ #include <node.h>
#include "ref_node_modules_builtin.h"
int main(int argc, char *argv[]) {
return node::Start(argc, argv);
} |
Thanks @tommyZZM , Glad we could help. In our case, we build a shared library with those static libraries and instruct the linker to include all symbols. Your solution also helps the linker include those symbols in the final binary. Good job. I'm closing this issue now, then :) |
reference this nodejs pull request nodejs/node#14986. |
one question: |
Hi @yhwang , Thanks for the question. This way to register modules is the one that is used in If module registering changes in The supported and released binaries use case is to use If you feel strongly about this change, I believe this would be a more useful discussion in Hope this was helpful. |
@jaimecbernardo thanks for the comments. I followed the link in nodejs to get here and I didn't notice that this is another repo. Sure, I will move the discussion back to nodejs and thanks for the sharing of shared/static lib usage. |
reference nodejs/node-v0.x-archive#7336 |
how does
NODE_STATIC_LIBRARY
work in this commit?7ee73e9 ios: Exports node.h symbols when building static
not found
NODE_STATIC_LIBRARY
definition searching in the remoteThe text was updated successfully, but these errors were encountered: