microsoft / vcpkg

C++ Library Manager for Windows, Linux, and MacOS
MIT License
23.17k stars 6.39k forks source link

Integration of grpc libraries into C++ project fails due to unresolved symbols #18021

Closed dhanuashikesh closed 3 years ago

dhanuashikesh commented 3 years ago

Description Integration of grpc.lib and related libraries into C++ project fails due to unresolved symbols. Might be similar to #10404

Environment

To Reproduce

  1. Steps to reproduce the behavior:
  2. vcpkg install grpc:x64-windows
  3. vcpkg integrate install
  4. Open Visual Studio 2019
  5. Create a new project > Console App (C++)
  6. Create an instance of grpc::ServerBuilder
  7. Build the project.

Failure logs

 CppServer.cpp
grpc.lib(iomgr_windows.cc.obj) : error LNK2019: unresolved external symbol __imp_WSAStartup referenced in function "void __cdecl winsock_init(void)" (?winsock_init@@YAXXZ)
grpc.lib(iomgr_windows.cc.obj) : error LNK2019: unresolved external symbol __imp_WSACleanup referenced in function "void __cdecl winsock_shutdown(void)" (?winsock_shutdown@@YAXXZ)
grpc.lib(socket_windows.cc.obj) : error LNK2019: unresolved external symbol __imp_bind referenced in function "void __cdecl probe_ipv6_once(void)" (?probe_ipv6_once@@YAXXZ)
grpc.lib(tcp_server_windows.cc.obj) : error LNK2001: unresolved external symbol __imp_bind
grpc.lib(tcp_client_windows.cc.obj) : error LNK2001: unresolved external symbol __imp_bind
grpc.lib(grpc_ares_ev_driver_windows.cc.obj) : error LNK2001: unresolved external symbol __imp_bind
grpc.lib(socket_windows.cc.obj) : error LNK2019: unresolved external symbol __imp_closesocket referenced in function "void __cdecl grpc_winsocket_shutdown(struct grpc_winsocket *)" (?grpc_winsocket_shutdown@@YAXPEAUgrpc_winsocket@@@Z)
grpc.lib(tcp_server_windows.cc.obj) : error LNK2001: unresolved external symbol __imp_closesocket
grpc.lib(tcp_client_windows.cc.obj) : error LNK2001: unresolved external symbol __imp_closesocket
address_sorting.lib(address_sorting_windows.c.obj) : error LNK2001: unresolved external symbol __imp_closesocket
grpc.lib(socket_windows.cc.obj) : error LNK2019: unresolved external symbol __imp_socket referenced in function "void __cdecl probe_ipv6_once(void)" (?probe_ipv6_once@@YAXXZ)
address_sorting.lib(address_sorting_windows.c.obj) : error LNK2001: unresolved external symbol __imp_socket
grpc.lib(resolve_address_windows.cc.obj) : error LNK2001: unresolved external symbol __imp_WSAGetLastError
grpc.lib(tcp_windows.cc.obj) : error LNK2001: unresolved external symbol __imp_WSAGetLastError
grpc.lib(grpc_ares_ev_driver_windows.cc.obj) : error LNK2001: unresolved external symbol __imp_WSAGetLastError
grpc.lib(socket_windows.cc.obj) : error LNK2001: unresolved external symbol __imp_WSAGetLastError
grpc.lib(iocp_windows.cc.obj) : error LNK2001: unresolved external symbol __imp_WSAGetLastError
grpc.lib(tcp_server_windows.cc.obj) : error LNK2001: unresolved external symbol __imp_WSAGetLastError
grpc.lib(tcp_client_windows.cc.obj) : error LNK2001: unresolved external symbol __imp_WSAGetLastError
grpc.lib(grpc_ares_ev_driver_windows.cc.obj) : error LNK2001: unresolved external symbol __imp_WSAIoctl
grpc.lib(socket_windows.cc.obj) : error LNK2001: unresolved external symbol __imp_WSAIoctl
grpc.lib(tcp_server_windows.cc.obj) : error LNK2001: unresolved external symbol __imp_WSAIoctl
grpc.lib(tcp_client_windows.cc.obj) : error LNK2001: unresolved external symbol __imp_WSAIoctl
grpc.lib(tcp_windows.cc.obj) : error LNK2001: unresolved external symbol __imp_WSAIoctl
grpc.lib(socket_windows.cc.obj) : error LNK2019: unresolved external symbol __imp_WSASocketA referenced in function "void __cdecl grpc_wsa_socket_flags_init(void)" (?grpc_wsa_socket_flags_init@@YAXXZ)
grpc.lib(tcp_server_windows.cc.obj) : error LNK2001: unresolved external symbol __imp_WSASocketA
grpc.lib(tcp_client_windows.cc.obj) : error LNK2001: unresolved external symbol __imp_WSASocketA
grpc.lib(grpc_ares_ev_driver_windows.cc.obj) : error LNK2001: unresolved external symbol __imp_WSASocketA
grpc.lib(iocp_windows.cc.obj) : error LNK2019: unresolved external symbol __imp_WSAGetOverlappedResult referenced in function "enum grpc_iocp_work_status __cdecl grpc_iocp_work(__int64)" (?grpc_iocp_work@@YA?AW4grpc_iocp_work_status@@_J@Z)
grpc.lib(tcp_server_windows.cc.obj) : error LNK2001: unresolved external symbol __imp_WSAGetOverlappedResult
grpc.lib(tcp_client_windows.cc.obj) : error LNK2001: unresolved external symbol __imp_WSAGetOverlappedResult
grpc.lib(grpc_ares_ev_driver_windows.cc.obj) : error LNK2001: unresolved external symbol __imp_WSAGetOverlappedResult
grpc.lib(tcp_server_windows.cc.obj) : error LNK2019: unresolved external symbol __imp_getpeername referenced in function "void __cdecl on_accept(void *,struct grpc_error *)" (?on_accept@@YAXPEAXPEAUgrpc_error@@@Z)
grpc.lib(tcp_server_windows.cc.obj) : error LNK2019: unresolved external symbol __imp_getsockname referenced in function "struct grpc_error * __cdecl prepare_socket(unsigned __int64,struct grpc_resolved_address const *,int *)" (?prepare_socket@@YAPEAUgrpc_error@@_KPEBUgrpc_resolved_address@@PEAH@Z)
grpc.lib(tcp_windows.cc.obj) : error LNK2001: unresolved external symbol __imp_getsockname
address_sorting.lib(address_sorting_windows.c.obj) : error LNK2001: unresolved external symbol __imp_getsockname
grpc.lib(tcp_server_windows.cc.obj) : error LNK2019: unresolved external symbol __imp_listen referenced in function "struct grpc_error * __cdecl prepare_socket(unsigned __int64,struct grpc_resolved_address const *,int *)" (?prepare_socket@@YAPEAUgrpc_error@@_KPEBUgrpc_resolved_address@@PEAH@Z)
grpc.lib(tcp_server_windows.cc.obj) : error LNK2019: unresolved external symbol __imp_setsockopt referenced in function "void __cdecl on_accept(void *,struct grpc_error *)" (?on_accept@@YAXPEAXPEAUgrpc_error@@@Z)
grpc.lib(tcp_windows.cc.obj) : error LNK2001: unresolved external symbol __imp_setsockopt
grpc.lib(resolve_address_windows.cc.obj) : error LNK2019: unresolved external symbol __imp_getaddrinfo referenced in function "struct grpc_error * __cdecl windows_blocking_resolve_address(char const *,char const *,struct grpc_resolved_addresses * *)" (?windows_blocking_resolve_address@@YAPEAUgrpc_error@@PEBD0PEAPEAUgrpc_resolved_addresses@@@Z)
grpc.lib(resolve_address_windows.cc.obj) : error LNK2019: unresolved external symbol __imp_freeaddrinfo referenced in function "struct grpc_error * __cdecl windows_blocking_resolve_address(char const *,char const *,struct grpc_resolved_addresses * *)" (?windows_blocking_resolve_address@@YAPEAUgrpc_error@@PEBD0PEAPEAUgrpc_resolved_addresses@@@Z)
grpc.lib(tcp_windows.cc.obj) : error LNK2019: unresolved external symbol __imp_WSARecv referenced in function "void __cdecl on_read(void *,struct grpc_error *)" (?on_read@@YAXPEAXPEAUgrpc_error@@@Z)
grpc.lib(tcp_windows.cc.obj) : error LNK2019: unresolved external symbol __imp_WSASend referenced in function "void __cdecl on_write(void *,struct grpc_error *)" (?on_write@@YAXPEAXPEAUgrpc_error@@@Z)
grpc.lib(grpc_ares_ev_driver_windows.cc.obj) : error LNK2001: unresolved external symbol __imp_WSASend
grpc.lib(socket_utils_windows.cc.obj) : error LNK2019: unresolved external symbol __imp_htonl referenced in function "unsigned int __cdecl grpc_htonl(unsigned int)" (?grpc_htonl@@YAII@Z)
address_sorting.lib(address_sorting.c.obj) : error LNK2001: unresolved external symbol __imp_htonl
grpc.lib(socket_utils_windows.cc.obj) : error LNK2019: unresolved external symbol __imp_htons referenced in function "unsigned short __cdecl grpc_htons(unsigned short)" (?grpc_htons@@YAGG@Z)
grpc.lib(grpc_ares_wrapper.cc.obj) : error LNK2001: unresolved external symbol __imp_htons
grpc.lib(parse_address.cc.obj) : error LNK2001: unresolved external symbol __imp_htons
grpc.lib(socket_utils_windows.cc.obj) : error LNK2019: unresolved external symbol __imp_ntohl referenced in function "unsigned int __cdecl grpc_ntohl(unsigned int)" (?grpc_ntohl@@YAII@Z)
grpc.lib(socket_utils_windows.cc.obj) : error LNK2019: unresolved external symbol __imp_ntohs referenced in function "unsigned short __cdecl grpc_ntohs(unsigned short)" (?grpc_ntohs@@YAGG@Z)
grpc.lib(grpc_ares_wrapper.cc.obj) : error LNK2001: unresolved external symbol __imp_ntohs
grpc.lib(socket_utils_windows.cc.obj) : error LNK2019: unresolved external symbol __imp_inet_pton referenced in function "int __cdecl grpc_inet_pton(int,char const *,void *)" (?grpc_inet_pton@@YAHHPEBDPEAX@Z)
grpc.lib(socket_utils_windows.cc.obj) : error LNK2019: unresolved external symbol inet_ntop referenced in function "char const * __cdecl grpc_inet_ntop(int,void const *,char *,unsigned __int64)" (?grpc_inet_ntop@@YAPEBDHPEBXPEAD_K@Z)
grpc.lib(ssl_transport_security.cc.obj) : error LNK2001: unresolved external symbol inet_ntop
grpc.lib(grpc_ares_ev_driver_windows.cc.obj) : error LNK2019: unresolved external symbol __imp_WSASetLastError referenced in function "public: __cdecl grpc_core::WSAErrorContext::~WSAErrorContext(void)" (??1WSAErrorContext@grpc_core@@QEAA@XZ)
grpc.lib(grpc_ares_ev_driver_windows.cc.obj) : error LNK2019: unresolved external symbol __imp_WSAConnect referenced in function "public: int __cdecl grpc_core::GrpcPolledFdWindows::ConnectUDP(class grpc_core::WSAErrorContext *,struct sockaddr const *,int)" (?ConnectUDP@GrpcPolledFdWindows@grpc_core@@QEAAHPEAVWSAErrorContext@2@PEBUsockaddr@@H@Z)
grpc.lib(grpc_ares_ev_driver_windows.cc.obj) : error LNK2019: unresolved external symbol __imp_WSARecvFrom referenced in function "public: void __cdecl grpc_core::GrpcPolledFdWindows::ContinueRegisterForOnReadableLocked(void)" (?ContinueRegisterForOnReadableLocked@GrpcPolledFdWindows@grpc_core@@QEAAXXZ)
address_sorting.lib(address_sorting_windows.c.obj) : error LNK2019: unresolved external symbol __imp_connect referenced in function address_sorting_create_source_addr_factory_for_current_platform
C:\Users\Ashikesh\source\repos\GrpcTest\x64\Debug\CppServer.exe : fatal error LNK1120: 27 unresolved externals

Expected behavior Shouldn't throw a linker error if all the header files are resolved properly.

Additional context

  1. vcpkg is compiled from github repo available on 5th May 2021.
  2. I have tried <VcpkgAutoLink>false</VcpkgAutoLink> but the linker error is reduced to following:
    CppServer.cpp
    CppServer.obj : error LNK2019: unresolved external symbol "public: __cdecl grpc::ServerBuilder::ServerBuilder(void)" (??0ServerBuilder@grpc@@QEAA@XZ) referenced in function main
    CppServer.obj : error LNK2019: unresolved external symbol "public: virtual __cdecl grpc::ServerBuilder::~ServerBuilder(void)" (??1ServerBuilder@grpc@@UEAA@XZ) referenced in function main
    C:\Users\Ashikesh\source\repos\GrpcTest\x64\Debug\CppServer.exe : fatal error LNK1120: 2 unresolved externals

EDIT: The vcpkg package was compiled on 20th May and not 5th May as previously stated.

lken274 commented 3 years ago

I am also having this issue. Actually, when I installed grpc my build completed fine. A few hours later and a restart, I'm getting various linking errors as well. Re-installing now doesn't seem to be solving anything.

EDIT: Solved, the problem was that at some point I used 'vcpkg integrate install'. To fix, I had to do 'vcpkg integrate remove', remove the CMAKE_TOOLCHAIN_FILE argument from my build command, and then add 'vcpkg\installed\x64-windows' to my PATH variable.

PhoebeHui commented 3 years ago

Duplicate of issue https://github.com/microsoft/vcpkg/issues/10404, thanks @lken274 for sharing the workaround, please use issue 10404 to track the status.

dhanuashikesh commented 3 years ago

I am also having this issue. Actually, when I installed grpc my build completed fine. A few hours later and a restart, I'm getting various linking errors as well. Re-installing now doesn't seem to be solving anything.

EDIT: Solved, the problem was that at some point I used 'vcpkg integrate install'. To fix, I had to do 'vcpkg integrate remove', remove the CMAKE_TOOLCHAIN_FILE argument from my build command, and then add 'vcpkg\installed\x64-windows' to my PATH variable.

Thanks for the workaround @lken274 . This works with the CMake build. Just a correction for the PATH, it should be vcpkg\installed\x64-windows\bin i.e the path to the library binaries.