Win10, Visual Studio 15 2017
That's what I've done so far:
cmake --build
on grpcAfter that my empty project including the pb-files compiled without an error.
Then I wrote some code to use and test grpc but when I try to compile this time, I'm getting several errors like
LNK2019 unresolved external symbol _address_sorting_init referenced in function "void __cdecl grpc_resolver_dns_ares_init(void)" (?grpc_resolver_dns_ares_init@@YAXXZ) grpc.lib(dns_resolver_ares.obj)
LNK2001 unresolved external symbol __imp__htons@4 grpc.lib(socket_utils_windows.obj)
LNK2019 unresolved external symbol _ares_gethostbyname referenced in function "struct grpc_ares_request * __cdecl grpc_dns_lookup_ares_continue_after_check_localhost_and_ip_literals_locked(char const *,char const *,char const *,struct grpc_pollset_set *,struct grpc_closure *,struct grpc_lb_addresses * *,bool,char * *,struct grpc_combiner *)" (?grpc_dns_lookup_ares_continue_after_check_localhost_and_ip_literals_locked@@YAPAUgrpc_ares_request@@PBD00PAUgrpc_pollset_set@@PAUgrpc_closure@@PAPAUgrpc_lb_addresses@@_NPAPADPAUgrpc_combiner@@@Z) grpc.lib(grpc_ares_wrapper.obj)
The first symbol "address_sorting_init" comes from the library address sorting present at https://github.com/grpc/grpc/tree/master/third_party/address_sorting
The second symbol is from the windows API library "ws2_32", the winsock library from Microsoft.
The third symbol is from the c-ares library: https://c-ares.haxx.se/
All 3 libraries are necessary for building grpc under Windows, so you should add them into your project.
The first error:
LNK2019 unresolved external symbol _address_sorting_init referenced in function "void __cdecl grpc_resolver_dns_ares_init(void)" (?grpc_resolver_dns_ares_init@@YAXXZ) grpc.lib(dns_resolver_ares.obj)
can be resolved by adding the address_sorting.lib. This lib is in the grpc build directory, same as grpc++.lib, grpc.lib and gpr.lib.
The second error:
LNK2001 unresolved external symbol __imp__htons@4 grpc.lib(socket_utils_windows.obj)
can be resolved by adding ws2_32.lib as per Nicolas suggested.
The third error:
LNK2019 unresolved external symbol _ares_gethostbyname referenced in function "struct grpc_ares_request * __cdecl grpc_dns_lookup_ares_continue_after_check_localhost_and_ip_literals_locked(char const *,char const *,char const *,struct grpc_pollset_set *,struct grpc_closure *,struct grpc_lb_addresses * *,bool,char * *,struct grpc_combiner *)" (?grpc_dns_lookup_ares_continue_after_check_localhost_and_ip_literals_locked@@YAPAUgrpc_ares_request@@PBD00PAUgrpc_pollset_set@@PAUgrpc_closure@@PAPAUgrpc_lb_addresses@@_NPAPADPAUgrpc_combiner@@@Z) grpc.lib(grpc_ares_wrapper.obj)
can be resolved by adding the cares.lib. You should be able to find this lib file under the third_party\cares\cares\lib directory inside the grpc build directory, no need to get it from elsewhere.
As a summary, suppose your grpc build directory is c:\grpc\.build, here are the libraries required for building a Release version application:
c:\grpc\.build\grpc++.lib
c:\grpc\.build\gpr.lib
c:\grpc\.build\grpc.lib
c:\grpc\.build\address_sorting.lib
c:\grpc\.build\third_party\protobuf\libprotobuf.lib
c:\grpc\.build\third_party\zlib.lib
c:\grpc\.build\third_party\cares\cares\lib\cares.lib
ws2_32.lib
If you want to build a Debug version of your application, please build a Debug version of grpc first, and then reference the libraries from the grpc debug version. To build a debug version with Ninja:
> md .debug
> cd .debug
> call "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvarsall.bat" x64
> cmake .. -GNinja -DCMAKE_BUILD_TYPE=Debug
> cmake --build .
Please change above directory of vcvarsall.bat according to your Visual Studio installation.
Please also note the Debug version of protobuf library file's name is libprotobufd.lib, not libprotobuf.lib.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With