CMake Build with Protobuf on Windows
To build Visual C++ projects on Windows that has dependency on Google protobuf library, we can use CMake. The executable of protobuf is not sufficient to compile C++ projects.
Dependency on protobuf
To specify a dependency on protobuf, the following line can be added into CMakeLists.txt file:
find_package(Protobuf REQUIRED)
Install protobuf library on Windows
- Follow this article to install Microsoft vcpkg on Windows: Microsoft vcpkg C++ Library Manager
- Install protobuf library using the following command:
vcpkg install protobuf:x64-windows
- Wait until the installation is completed:
Test the dependency
- Create a test CMake project with the following lists (CMakeLists.txt):
cmake_minimum_required(VERSION 3.10) # set the project name project(Test) # Find package find_package(OpenSSL REQUIRED) find_package(Protobuf REQUIRED)
- Run the build command (under project folder path, for my environment, it locates in C:\hdp\cmaketest):
cmake .
- The output looks like the following:
C:\hdp\cmaketest>cmake . -- Building for: Visual Studio 14 2015 -- Selecting Windows SDK version to target Windows 10.0.18363. -- The C compiler identification is MSVC 19.0.24215.1 -- The CXX compiler identification is MSVC 19.0.24215.1 -- Detecting C compiler ABI info -- Detecting C compiler ABI info - done -- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/cl.exe - skipped -- Detecting C compile features -- Detecting C compile features - done -- Detecting CXX compiler ABI info -- Detecting CXX compiler ABI info - done -- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/cl.exe - skipped -- Detecting CXX compile features -- Detecting CXX compile features - done -- Found OpenSSL: C:/dev/vcpkg/installed/x64-windows/lib/libcrypto.lib (found version "1.1.1i") -- Found Protobuf: C:/dev/vcpkg/installed/x64-windows/lib/libprotobuf.lib (found version "3.14.0") -- Configuring done -- Generating done -- Build files have been written to: C:/hdp/cmaketest
copyright
This page is subject to Site terms.
comment Comments
No comments yet.