0

My project require protobuf 3.5.1, I built it and want cmake use it instead of installed in system (2.5.0). It is my CMakeLists.txt

cmake_minimum_required(VERSION 3.8)

project(test)

set(ENV{PKG_CONFIG_PATH} "/path_to_protobuf/lib/pkgconfig:$ENV{PKG_CONFIG_PATH}")

set(CMAKE_CXX_STANDARD 14)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOMOC ON)

find_package(Protobuf 3.5.1 REQUIRED)

link_directories(
        ${PROTOBUF_LIBRARY_DIRS}
)

include_directories(
        src
        ${PROTOBUF_INCLUDE_DIRS}

)

protobuf_generate_cpp(
        PROTO_SRCS PROTO_HDRS
        ../my_proto.proto
)

set(sourceDir "${PROJECT_SOURCE_DIR}/src")
file(GLOB_RECURSE allFiles "${sourceDir}/*.h" "${sourceDir}/*.cpp")

add_executable(
        test
        ${allFiles}
        ${PROTO_SRCS}
        ${PROTO_HDRS})

target_link_libraries(
        test
        ${PROTOBUF_LIBRARIES}
)

But cmake finishes with error message:

CMake Warning at lib_build/share/cmake-3.11/Modules/FindProtobuf.cmake:455 (message):
  Protobuf compiler version 3.5.1 doesn't match library version 2.5.0
Call Stack (most recent call first):
  CMakeLists.txt:36 (find_package)


CMake Error at lib_build/share/cmake-3.11/Modules/FindPackageHandleStandardArgs.cmake:137 (message):
  Could NOT find Protobuf: Found unsuitable version "2.5.0", but required is
  at least "3.5.1" (found /usr/lib64/libprotobuf.so;-lpthread)
Call Stack (most recent call first):
  lib_build/share/cmake-3.11/Modules/FindPackageHandleStandardArgs.cmake:376 (_FPHSA_FAILURE_MESSAGE)
  lib_build/share/cmake-3.11/Modules/FindProtobuf.cmake:543 (FIND_PACKAGE_HANDLE_STANDARD_ARGS)
  CMakeLists.txt:36 (find_package)


— Configuring incomplete, errors occurred!
See also "/home/user/app/CMakeFiles/CMakeOutput.log".
See also "/home/user/app/CMakeFiles/CMakeError.log".

How to specify module search path correctly? Can I do that without writing self FindProtobuf.cmake file?

mgukov
  • 493
  • 5
  • 18
  • 2
    The error message says, `Found unsuitable version "2.5.0", but required is at least "3.5.1"` – Justin Apr 10 '18 at 18:59
  • `find_package(Protobuf 3.5.1 REQUIRED)` specifies that `3.5.1` is the minimum. If you think the restriction is wrong you can try reducing the version requirement otherwise install a newer version.. – drescherjm Apr 10 '18 at 19:06
  • My question: How to specify to cmake the path to find the correct version of the library? I built protobuf 3.5.1 from sources and install it to /path_to_protobuf. – mgukov Apr 10 '18 at 19:13
  • And I can't install the updated version of the library in the system. – mgukov Apr 10 '18 at 19:15
  • The question is not in a specific version, but how to correctly specify the path where cmake look for libraries – mgukov Apr 10 '18 at 19:56
  • 3
    Usually, setting `CMAKE_PREFIX_PATH` variable to the library's installation prefix is sufficient for find that library. In your case, pass `-DCMAKE_PREFIX_PATH=/path_to_protobuf` option for `cmake` invocation. Do not forget to clear CMake cache (`CMakeCache.txt` file in build directory) before such reconfiguration. – Tsyvarev Apr 10 '18 at 20:00
  • @Tsyvarev, thank you, your solution works, question closed. – mgukov Apr 10 '18 at 20:46

0 Answers0