未定义必需的目标protobuf :: libprotobuf-lite或protobuf :: libprotobuf

时间:2019-02-03 14:49:54

标签: cmake protocol-buffers

尝试编译Valhalla应用程序时出现错误 我试图使用CMAKE编译此代码:

find_package(Protobuf REQUIRED)
message("   --> PROTOBUF LIB: ${PROTOBUF_LIBRARIES}")
message("   --> PROTOBUF INCLUDE: ${PROTOBUF_INCLUDE_DIRS}")
message("   --> PROTOBUF VERSION: ${Protobuf_VERSION}")
message("   --> PROTOBUF Found: ${Protobuf_FOUND}")

if(EXISTS protobuf::libprotobuf-lite)
  set(valhalla_protobuf_targets protobuf::libprotobuf-lite)
elseif(EXISTS protobuf::libprotobuf)
  set(valhalla_protobuf_targets protobuf::libprotobuf)
else()
  message(FATAL_ERROR "Required target protobuf::libprotobuf-lite or protobuf::libprotobuf is not defined")
endif()

这是提供错误的CMAKE代码:

-- Found Protobuf: /usr/local/lib/libprotobuf.so;-pthread;-pthread (found version "3.6.1")
--> PROTOBUF LIB: /usr/local/lib/libprotobuf.so;-pthread;-pthread
--> PROTOBUF INCLUDE: /usr/local/include
--> PROTOBUF VERSION: 3.6.1
--> PROTOBUF Found: TRUE
CMake Error at CMakeLists.txt:143 (message):
Required target protobuf::libprotobuf-lite or protobuf::libprotobuf is not defined

我不明白为什么这段代码会给我一个错误“未定义必需的目标protobuf :: libprotobuf-lite或protobuf :: libprotobuf”

我试图更改TARGET上的EXISTS,但是什么也没发生,结果是一样的

if(TARGET protobuf::libprotobuf-lite)
 set(valhalla_protobuf_targets protobuf::libprotobuf-lite)
elseif(TARGET protobuf::libprotobuf)
 set(valhalla_protobuf_targets protobuf::libprotobuf)
else()
 message(FATAL_ERROR "Required target protobuf::libprotobuf-lite or protobuf::libprotobuf is not defined")
endif()

有人可以帮助我吗?我花了大约2天的时间来解决这个问题

2 个答案:

答案 0 :(得分:0)

version 3.7的脚本FindProtobuf.cmake中,没有关于protobuf::*目标的概念:该脚本仅设置变量。自version 3.9起,导入的目标由脚本设置。

答案 1 :(得分:0)

在我构建了cmake 3.13并安装它之后,我尝试构建valhall,但是仍然没有结果。...我伤了头,但不理解原因是“>”:

if(TARGET protobuf::libprotobuf-lite>)
  set(valhalla_protobuf_targets protobuf::libprotobuf-lite)
elseif(TARGET protobuf::libprotobuf>)
  set(valhalla_protobuf_targets protobuf::libprotobuf)
else()
  message(FATAL_ERROR "Required target protobuf::libprotobuf-lite or protobuf::libprotobuf is not defined")
endif()

我删除“>”构建成功后!