When building a project on Windows using CMake, I got this error:
Could NOT find Protobuf (missing: Protobuf_LIBRARIES Protobuf_INCLUDE_DIR)
Call Stack (most recent call first):
C:/CMake/share/cmake-3.25/Modules/FindPackageHandleStandardArgs.cmake:600 (_FPHSA_FAILURE_MESSAGE)
C:/CMake/share/cmake-3.25/Modules/FindProtobuf.cmake:650 (FIND_PACKAGE_HANDLE_STANDARD_ARGS)
cmake/protobuf.cmake:1 (find_package)
CMakeLists.txt:256 (include)
The solution is to build and install Protobuf yourself.
- download Protobuf source code, extract to a directory such as C:\Protobuf, create a build directory such as C:\Protobufbuild
- cmake -G Ninja -S C:\Protobuf -B C:\Protobufbuild -DCMAKE_INSTALL_PREFIX=C:\protobuf-21.12
- cd to C:\Protobufbuild and execute ninja install
- cmake -G Ninja -DProtobuf_LIBRARIES=C:\protobuf-21.12\lib -DProtobuf_INCLUDE_DIR=C:\protobuf-21.12\include -DCMAKE_INSTALL_PREFIX=C:\projectinstalldir -S C:\projectsourcedir -B C:\projectbuilddir
Note that don’t download and install the pre-built Protobuf binaries such as protoc-21.12-win64.zip as Protocol Buffers official website tells you to do because some files such as whole libs and some include files are missing in the pre-built package.