This repository is supposed to document issues that are observed when trying to use gRPC (built as static libraries) in a project composed of DLLs under Windows.
Currently, there are two examples:
One DLL defines a class, that creates a grpc::ClientContext, and the other DLL creates an instance of that class and passes the ClientContext to a gRPC call, which results in an access violation later at the destruction of the ClientContext. The repository does not contain any implementation of a server component since an actual connection is not required to trigger the issue and this approach simplifies the example. Feel free to uncomment the define in GrpClient1.cpp to switch to an implementation that does not result in any issues to verify, that this is not about the missing server part.
(This one looks more like a general bug than an issue due to DLL usage. I created a bug report for that) A DLL provides a singleton of a class that wraps the gRPC service client (using the PIMPL idiom). The executable gets an instance of the singleton (actually nothing happens beyond instantiation of a channel object) and the process blocks indefinitely on shutdown. This one might have a completely different background than the other example (gRPC libs are only linked into one DLL, so no duplicate static gRPC data) and the result also seems to be flaky: If the environment variables GRPC_VERBOSITY=debug and GRPC_TRACE=all are set to enable debugging, the process ends without issues.
The project as well as gRCP were built with Visual Studio 2019.
To build gRPC, these were the steps that were used
git clone https://github.com/grpc/grpc
cd grpc
git submodule update --init
The following will install gRPC in the folder c:\temp\grpc
(last parameter in the long config command) which is also used in the cmake file of this repo. Feel free to change it at both locations.
md .build
cd .build
cmake .. -G "Visual Studio 16 2019" -DgRPC_BUILD_GRPC_PYTHON_PLUGIN=OFF -DgRPC_BUILD_GRPC_PHP_PLUGIN=OFF -DgRPC_BUILD_GRPC_RUBY_PLUGIN=OFF -DgRPC_BUILD_GRPC_OBJECTIVE_C_PLUGIN=OFF -DgRPC_BUILD_GRPC_NODE_PLUGIN=OFF -DgRPC_BUILD_GRPC_CSHARP_PLUGIN=OFF -DgRPC_BUILD_CSHARP_EXT=OFF -DABSL_ENABLE_INSTALL=ON -DCMAKE_INSTALL_PREFIX="c:/temp/grpc"
cmake --build . --config Release
cmake --install .
After successful build and install of gRPC as described above, you can build this repository.
- Clone this repository
- Open the folder in Visual Studio 2019
- Generate the cmake cache
- Build
- Run the target AccessViolationExample.exe (Install) or InfiniteBlockExample.exe (Install)