Open2

nccc: macOS版nodeのネイティブモジュールを手作りする

okuokuokuoku

なんかリンクエラーになる

Undefined symbols for architecture x86_64:
  "_napi_call_function", referenced from:
      _nccc_cb_dispatcher in node-nccc.c.o
  "_napi_close_handle_scope", referenced from:
      _nccc_cb_dispatcher in node-nccc.c.o
      _nccc_cb_dispatcher in node-nccc.c.o
  "_napi_create_array_with_length", referenced from:
      _make_nccc_cb in node-nccc.c.o
      _nccc_call_trampoline in node-nccc.c.o
  "_napi_create_buffer", referenced from:
      _value_out in node-nccc.c.o
  "_napi_create_double", referenced from:
      _value_in in node-nccc.c.o
      _value_in in node-nccc.c.o

Windowsではインポートライブラリ(*.lib)があるけど、macOSとかLinuxには無いもんな。

okuokuokuoku

とりあえず -Wl,-undefined,dynamic_lookup 足す

https://github.com/okuoku/nccc/commit/55fe6d57d107e235dfc7ea389ff57ee67da10c52#diff-376987bca10491955c9d4ef1a282453210f76909f9613ce5add472d581099166R32-R35

う〜ん...

リンクできるしちゃんと動くんだけど、これ不健康だよなぁ。。

okuoku@prism build % node
Welcome to Node.js v18.17.1.
Type ".help" for more information.
> require("./node-nccc")
{
  make_nccc_cb: [Function: make_nccc_cb],
  make_nccc_call: [Function: make_nccc_call],
  destroy_cb_ctx: [Function: destroy_cb_ctx],
  wrap_pointer: [Function: wrap_pointer],
  corelib: {
    util_rawcall: [External: 11a9b6530],
    util_peek_u64: [External: 11a9b6580],
    util_peek_u32: [External: 11a9b65b0],
    util_peek_u8: [External: 11a9b65e0],
    util_peek_ptr: [External: 11a9b6610],
    util_poke_u64: [External: 11a9b6640],
    util_poke_u32: [External: 11a9b6670],
    util_malloc: [External: 11a9b66a0],
    util_free: [External: 11a9b66f0],
    util_ptraddr: [External: 11a9b6720],
    dlfcn_open: [External: 11a9b6a60],
    dlfcn_get: [External: 11a9b6ad0]
  }
}
>