How to fix CMake Protobuf "FindThreads only works if either C or CXX language is enabled"

Problem:

When trying to configure your CMake project using

CMakeLists_find_protobuf.txt
find_package(Protobuf REQUIRED)

you see an error message like

example.txt
CMake Error at /usr/share/cmake-3.16/Modules/FindThreads.cmake:49 (message):
  FindThreads only works if either C or CXX language is enabled
Call Stack (most recent call first):
  /usr/share/cmake-3.16/Modules/FindProtobuf.cmake:420 (find_package)
  CMakeLists.txt:7 (find_package)

-- Configuring incomplete, errors occurred!

Solution

You need to put your

CMakeLists_project.txt
project(MyProject)

line before the

CMakeLists_find_protobuf_after_project.txt
find_package(Protobuf REQUIRED)

line. If you don’t have a project() line, create one.


Check out similar posts by category: C/C++, CMake