Search code examples
visual-studiodllprotocol-buffersvcpkg

Visual Studio 2019 and vcpkg not linking to debug dlls


I'm trying to use protobuf in my application as dlls (libprotobuf-lite.dll and libprotobuf.dll). I installed protobuf using vcpkg, and everything works perfectly fine in the Release configuration. However, if I build my solution (using Visual Studio) in Debug configuration, I get debug assertion errors. I was able to track this down to a problem with the protobuf dlls used.

If I compile the solution, Visual Studio (or vcpkg) copies the necessary dlls from the vcpkg folder to the solution folder. As I said, this works perfectly fine for Release. However, in Debug, it copies the same dlls instead of the debug dlls (libprotobufd.dll and libprotobuf-lited.dll).

So my question is: How can I configure vcpkg and Visual Studio 2019 such that it uses the correct dlls?


Solution

  • Unfortunately, you haven't provided a minimal reproducible example, so I'm not sure which one of these can be the failure point in your setup:

    1. Please ensure that for your Debug project configuration, you have selected in Project properties -> vcpkg -> Vcpkg configuration to Debug. Don't forget to fully rebuild the solution after changing this.

      enter image description here

      I tested this (although I have VS2022 here) and for me it changes which DLLs are being used.

    2. Ensure you are using the latest vcpkg version and that you properly installed its VS integration with vcpkg integrate install command (requires Administrative command prompt).

    3. Verify that you built your proto files with the same vcpkg copy. It's best to build them as part of your project. You can see how to add custom build tool here. You can use this command line for the build step:

      $(VcpkgRoot)/installed/$(VcpkgTriplet)/tools/protobuf/protoc.exe %(Filename).proto --cpp_out=$(ProjectDir)

    If all this doesn't help. An MRE or verbose build logs from your project might help to understand the root cause for the behavior you observe.