我有cmake 3.10.x,并下载了当前的protobuf源码3.6.1。我使用cmake创建了bin目录“ {PROTOBUF_SOURCE_DIR} / bin”,此库已成功建立。下一步,我想在基于cmake的项目中使用此自定义树。我有
set ( Protobuf_USE_STATIC_LIBS ON )
find_package( Protobuf REQUIRED )
if ( Protobuf_FOUND )
message( STATUS "Protobuf version : ${Protobuf_VERSION}" )
message( STATUS "Protobuf include path : ${Protobuf_INCLUDE_DIRS}" )
message( STATUS "Protobuf libraries : ${Protobuf_LIBRARIES}" )
else()
message( WARNING "Protobuf package not found -> specify search path via PROTOBUF_ROOT variable")
endif()
但是如何为cmake指定我的自定义目录树以查找必要的内容。
如果我使用find_package( Protobuf REQUIRED PATHS ${PROTOBUF_ROOT}/bin/lib/cmake/protobuf )
,那么我将从cmake看到以下输出:
Protobuf version : 3.6.1
Protobuf include path :
Protobuf libraries :
如何使cmake查找包含路径,库和协议编译器?
答案 0 :(得分:1)
最后我有了一个解决方案-也许它将为其他人节省很多时间
set ( Protobuf_USE_STATIC_LIBS ON )
include(${PROTOBUF_ROOT}/bin/lib/cmake/protobuf/protobuf-config.cmake)
include(${PROTOBUF_ROOT}/bin/lib/cmake/protobuf/protobuf-module.cmake)
include(${PROTOBUF_ROOT}/bin/lib/cmake/protobuf/protobuf-options.cmake)
include(${PROTOBUF_ROOT}/bin/lib/cmake/protobuf/protobuf-targets.cmake)
find_package( Protobuf REQUIRED HINTS ${PROTOBUF_ROOT}/bin/lib/cmake/protobuf )
if ( Protobuf_FOUND )
message( STATUS "Protobuf version : ${Protobuf_VERSION}" )
message( STATUS "Protobuf include path : ${Protobuf_INCLUDE_DIRS}" )
message( STATUS "Protobuf libraries : ${Protobuf_LIBRARIES}" )
message( STATUS "Protobuf compiler libraries : ${Protobuf_PROTOC_LIBRARIES}")
message( STATUS "Protobuf lite libraries : ${Protobuf_LITE_LIBRARIES}")
else()
message( WARNING "Protobuf package not found -> specify search path via PROTOBUF_ROOT variable")
endif()
答案 1 :(得分:0)
这对我很有用,指向我的自定义 Windows 静态构建:
model.wv.most_similar("glass")
由于某种原因,设置 set(Protobuf_USE_STATIC_LIBS ON)
# add parent directory containing bin/protoc.exe, cmake/protobuf-config.cmake, lib/libprotobufd.lib (or .a), etc.
list(APPEND CMAKE_PREFIX_PATH "/dir/where/protobuf/was/installed")
find_package(Protobuf REQUIRED)
或 Protobuf_DIR
不起作用。