其他分享
首页 > 其他分享> > 低版本protobuf与cmake问题:Could not find a package configuration file provided by "Protobuf" wit

低版本protobuf与cmake问题:Could not find a package configuration file provided by "Protobuf" wit

作者:互联网

背景

如果使用Cmake编译caffe, 且使用低版本protobuf(如2.5),会报错cmake找不到protobuf。

解决思路:

更改caffe工程默认cmake文件,使用pkg-config寻找。

解决办法:

修改报错的cmake文件,路径在caffe工程下cmake/ProtoBuf.cmake, 修改如下两处

# Finds Google Protocol Buffers library and compilers and extends

# 修改点1:
########################
# 改用pkg-config查找包
set(ENV{PKG_CONFIG_PATH} /home/timber/Library/lib/pkgconfig)
#find_package( Protobuf REQUIRED )# 注释掉
find_package(PkgConfig)
pkg_search_module( Protobuf  REQUIRED protobuf)
#########################

list(APPEND Caffe_INCLUDE_DIRS PUBLIC ${PROTOBUF_INCLUDE_DIR})
list(APPEND Caffe_LINKER_LIBS PUBLIC ${PROTOBUF_LIBRARIES})

# As of Ubuntu 14.04 protoc is no longer a part of libprotobuf-dev package
# and should be installed separately as in: sudo apt-get install protobuf-compiler
if(EXISTS ${PROTOBUF_PROTOC_EXECUTABLE})
  message(STATUS "Found PROTOBUF Compiler: ${PROTOBUF_PROTOC_EXECUTABLE}")
else()
  message(FATAL_ERROR "Could not find PROTOBUF Compiler")
endif()

# 修改点2:
##########################
# 强行设置成ON
set(PROTOBUF_FOUND ON)
if(PROTOBUF_FOUND)
##########################      
  # fetches protobuf version
  caffe_parse_header(${PROTOBUF_INCLUDE_DIR}/google/protobuf/stubs/common.h VERION_LINE GOOGLE_PROTOBUF_VERSION)
  string(REGEX MATCH "([0-9])00([0-9])00([0-9])" PROTOBUF_VERSION ${GOOGLE_PROTOBUF_VERSION})
  set(PROTOBUF_VERSION "${CMAKE_MATCH_1}.${CMAKE_MATCH_2}.${CMAKE_MATCH_3}")
  unset(GOOGLE_PROTOBUF_VERSION)
endif()

# place where to generate protobuf sources
set(proto_gen_folder "${PROJECT_BINARY_DIR}/include/caffe/proto")
include_directories("${PROJECT_BINARY_DIR}/include")

set(PROTOBUF_GENERATE_CPP_APPEND_PATH TRUE)

标签:provided,set,cmake,protobuf,VERSION,caffe,PROTOBUF
来源: https://www.cnblogs.com/geoffreyone/p/15535529.html