I'm trying to compile this project: https://github.com/shaochuan/cmake-protobuf-example. I successfully compiled protobuf with msvc2015 (x64). The check project runs without errors (All result: PASSED).
I set up the project in cmake, provided all the paths:
Protobuf_INCLUDE_DIR=C:/TK/protobuf-330/msvc2015_64/install/include
Protobuf_LIBRARY_DEBUG=C:/TK/protobuf-330/msvc2015_64/install/lib/libprotobufd.lib
Protobuf_LITE_LIBRARY_DEBUG=C:/TK/protobuf-330/msvc2015_64/install/lib/libprotobuf-lited.lib
Protobuf_PROTOC_EXECUTABLE=C:/TK/protobuf-330/msvc2015_64/install/bin/protoc.exe
Protobuf_PROTOC_LIBRARY_DEBUG=C:/TK/protobuf-330/msvc2015_64/install/lib/libprotocd.lib
Protobuf_SRC_ROOT_FOLDER=C:\TK\src\protobuf-330\src
The proto-project compiles without any error. It includes the message.cc and message.h files. The CMakeLists.txt looks like this:
INCLUDE(FindProtobuf)
FIND_PACKAGE(Protobuf REQUIRED)
INCLUDE_DIRECTORIES(${PROTOBUF_INCLUDE_DIR})
PROTOBUF_GENERATE_CPP(PROTO_SRC PROTO_HEADER message.proto)
ADD_LIBRARY(proto ${PROTO_HEADER} ${PROTO_SRC})
If I compile the main project with the following CMakeLists.txt:
PROJECT(rpc)
CMAKE_MINIMUM_REQUIRED (VERSION 2.6)
ADD_SUBDIRECTORY(proto)
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR})
ADD_EXECUTABLE(main main.cpp)
TARGET_LINK_LIBRARIES(main proto ${PROTOBUF_LIBRARY})
and then build it, I receive this error (C1083) saying:
"Cannot open include file: 'google/protobuf/stubs/common.h': No such file or directory" c:\tktest\protobuftest\src\proto\message.pb.h
In the file the erroneous line is:
#include <google/protobuf/stubs/common.h>
I cannot figure out what went wrong.Any hints are appreciated. Are there some known problems regarding cmake + protobuf + visual studio 2015? Thanks in advance.
In your CMakeLists.txt you should replace PROTOBUF_INCLUDE_DIR with Protobuf_INCLUDE_DIR or Protobuf_INCLUDE_DIRS (note the S at the end) and PROTOBUF_LIBRARY with Protobuf_LIBRARY or Protobuf_LIBRARIES. CMake variable names are case sensitive. I just checked with the CMake 3.9 version. The FindProtobuf.cmake module which is implicitely called when using find_package(Protobuf) defines those variables when run successful.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With