access_time 7 months ago languageEnglish
more_vert

CMake Build with Protobuf on Windows

visibility 222 comment 0

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

  1. Follow this article to install Microsoft vcpkg on Windows: Microsoft vcpkg C++ Library Manager 
  2. Install protobuf library using the following command:
    vcpkg install protobuf:x64-windows
  3. Wait until the installation is completed:

Test the dependency

  1. 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)
  2. Run the build command (under project folder path, for my environment, it locates in C:\hdp\cmaketest):
    cmake .
  3. 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.
Like this article?
Share on

Please log in or register to comment.

account_circle Log in person_add Register

Log in with external accounts

Follow Kontext

Get our latest updates on LinkedIn.

Want to contribute on Kontext to help others?

Learn more

More from Kontext

visibility 229
thumb_up 0
access_time 7 months ago
visibility 10903
thumb_up 0
access_time 6 years ago
visibility 4516
thumb_up 1
access_time 13 months ago