uNetworking / uSockets

Miniscule cross-platform eventing, networking & crypto for async applications
Apache License 2.0
1.29k stars 267 forks source link

[Windows + MSVC 14.29.30133] usockets.lib(libuv.obj) : error LNK2001: unresolved external symbol uv_poll_init_socket #159

Closed yesudeep closed 3 years ago

yesudeep commented 3 years ago

Error when building a usockets test example with LIBUS_USE_LIBUV=1 defined.

❯ bazel run //third_party/cc/test:usockets_example
...
  C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.29.30133/bin/HostX64/x64/link.exe @bazel-out/x64_windows-fastbuild/bin/third_party/cc/test/usockets_example.exe-2.params
Execution platform: @local_config_platform//:host
   Creating library bazel-out\x64_windows-fastbuild\bin\third_party\cc\test\usockets_example.lib and object bazel-out\x64_windows-fastbuild\bin\third_party\cc\test\usockets_example.exp
usockets.lib(libuv.obj) : error LNK2001: unresolved external symbol uv_poll_init_socket
bazel-out\x64_windows-fastbuild\bin\third_party\cc\test\usockets_example.exe : fatal error LNK1120: 1 unresolved externals
Target //third_party/cc/test:usockets_example failed to build
...

OS and compiler:

Compiler: MSVC/14.29.30133 OS: Windows 11 (x86_64)

Probable cause:

The uv_poll_init_socket API function has been removed from libuv.

See: https://github.com/libuv/libuv/pull/1166

ghost commented 3 years ago

uv_poll_init_socket is definitely not removed and even if it was, it wouldn't give you a linker error it would give you a compiler error. You just need to figure out how to twist all those fancy Bazel knobs of yours.

yesudeep commented 3 years ago

I'm not sure which Bazel knobs I'd have to turn on to get the compiler to warn me, but I'll certainly look into it.

  1. It also turns out that I'm currently tracking the master branch of libuv and the function has clearly been removed. This is the only reference to the function on that branch:
libuv on  master took 3m4s
❯ git grep 'uv_poll_init_socket'
docs/code/uvwget/main.c:    int r = uv_poll_init_socket(loop, &context->poll_handle, sockfd);

I'll see whether I can switch to an older branch to accommodate building uSockets, but it's likely this change will affect uSockets in the future.

  1. Secondly, it's possible I've run into a quirk of C, where an implicit declaration for uv_poll_init_socket is created by the compiler, which should have been a warning on MSVC. However, clang warns me:
❯ bazel run //third_party/cc/test:usockets_example
...
INFO: Analyzed target //third_party/cc/test:usockets_example (32 packages loaded, 768 targets configured).
INFO: Found 1 target...
INFO: From Compiling src/eventing/libuv.c:
external/usockets/src/eventing/libuv.c:88:5: warning: implicit declaration of function 'uv_poll_init_socket' is invalid in C99 [-Wimplicit-function-declaration]
    uv_poll_init_socket(loop->uv_loop, p->uv_p, p->fd);
    ^
1 warning generated.
INFO: From Compiling src/unix/udp.c:
external/libuv/src/unix/udp.c:951:3: warning: ISO C90 forbids mixing declarations and code [-Wdeclaration-after-statement]
  STATIC_ASSERT(sizeof(mreq.gsr_group) >= sizeof(*multicast_addr));
  ^
external/libuv/src/uv-common.h:52:8: note: expanded from macro 'STATIC_ASSERT'
  void uv__static_assert(int static_assert_failed[1 - 2 * !(expr)])
       ^
1 warning generated.
ERROR: /usr/home/yesudeep/code/foo/third_party/cc/test/BUILD.bazel:460:10: Linking third_party/cc/test/usockets_example failed: (Exit 1): clang failed: error executing command
...
  /usr/bin/clang -o bazel-out/freebsd-fastbuild/bin/third_party/cc/test/usockets_example bazel-out/freebsd-fastbuild/bin/third_party/cc/test/_objs/usockets_example/usockets_example.pic.o bazel-out/freebsd-fastbuild/bin/external/fmt/libfmt.a bazel-out/freebsd-fastbuild/bin/external/usockets/libusockets.a bazel-out/freebsd-fastbuild/bin/external/boringssl/libssl.a bazel-out/freebsd-fastbuild/bin/external/boringssl/libcrypto.a bazel-out/freebsd-fastbuild/bin/external/libuv/liblibuv.a bazel-out/freebsd-fastbuild/bin/external/com_microsoft_mimalloc/libmimalloc.a -pthread -lpthread -lpthread -ldl -lm -pthread -lm -Wl,-S -lstdc++ -Wl,-z,relro,-z,now -no-canonical-prefixes)
Execution platform: @local_config_platform//:host
ld: error: undefined symbol: uv_poll_init_socket
>>> referenced by libuv.c
>>>               libuv.pic.o:(us_poll_start) in archive bazel-out/freebsd-fastbuild/bin/external/usockets/libusockets.a
clang: error: linker command failed with exit code 1 (use -v to see invocation)

HTH.

ghost commented 3 years ago

Show me the exact commit it was removed.

e3dio commented 3 years ago

https://github.com/libuv/libuv/commit/68dafe9016e35e31bf1a7ba8482a3d566c43a86b#diff-73a07d2c376f29ebf2305df2b93b4abed5a4918fe1aa69b7856dfe794c4990b8

ghost commented 3 years ago

What version does Node.js use?

ghost commented 3 years ago

Okay for some reason Node.js 16 is still on libuv 1.x and this changed back in 2017 for 2.0. Okay we are not compatible with libuv 2.