英文:
Compile protobuf to c++, cmake connot find the dir
问题
这是我的CMakeLists.txt文件:
cmake_minimum_required(VERSION 3.25)
SET(MESSAGE_DIR "/home/dbn/work/seal/cmd/protogen")
if(EXISTS "${CMAKE_BINARY_DIR}/cmd/proto" AND IS_DIRECTORY "${CMAKE_BINARY_DIR}/cmd/proto")
SET(PROTO_META_BASE_DIR ${MESSAGE_DIR})
else()
file(MAKE_DIRECTORY ${MESSAGE_DIR})
SET(PROTO_META_BASE_DIR ${MESSAGE_DIR})
endif()
LIST(APPEND PROTO_FLAGS -I${CMAKE_SOURCE_DIR}/proto)
file(GLOB_RECURSE MSG_PROTOS ${CMAKE_SOURCE_DIR}/proto/*.proto)
set(MESSAGE_SRC "")
set(MESSAGE_HDRS "")
foreach(msg ${MSG_PROTOS})
get_filename_component(FIL_WE ${msg} NAME_WE)
list(APPEND MESSAGE_SRC "${CMAKE_SOURCE_DIR}/proto/${FIL_WE}.pb.cc")
list(APPEND MESSAGE_HDRS "${CMAKE_SOURCE_DIR}/proto/${FIL_WE}.pb.h")
add_custom_command(
OUTPUT "${CMAKE_SOURCE_DIR}/proto/${FIL_WE}.pb.cc"
"${CMAKE_SOURCE_DIR}/proto/${FIL_WE}.pb.h"
COMMAND ${PROTOBUF_PROTOC_EXECUTABLE}
ARGS --cpp_out=${PROTO_META_BASE_DIR} -I${CMAKE_SOURCE_DIR} ${msg}
DEPENDS ${msg}
COMMENT "Running C++ protocol buffer compiler on ${msg}"
VERBATIM
)
endforeach()
当我编译它时,出现了这个错误:
[33%] Running C++ protocol buffer compiler on /home/dbn/work/seal/cmd/proto/test.proto
/bin/sh: -I/home/dbn/work/seal/cmd: No such file or directory
[66%] Running C++ protocol buffer compiler on /home/dbn/work/seal/cmd/proto/person.proto
/bin/sh: -I/home/dbn/work/seal/cmd: No such file or directory
[100%] generate message target
但实际上,目录'/home/dbn/work/seal/cmd/proto'是存在的。
当前工作目录:
pwd
/home/dbn/work/seal/cmd
我尝试将ARGS --cpp_out=${PROTO_META_BASE_DIR} -I${CMAKE_SOURCE_DIR} ${msg}
更改为ARGS --cpp_out=${PROTO_META_BASE_DIR} -I=${CMAKE_SOURCE_DIR} ${msg}
但没有用。
英文:
This is my cmakelist.txt
cmake_minimum_required(VERSION 3.25)
SET(MESSAGE_DIR "/home/dbn/work/seal/cmd/protogen")
if(EXISTS "${CMAKE_BINARY_DIR}cmd/proto" AND IS_DIRECTORY "${CMAKE_BINARY_DIR}/cmd/pro
SET(PROTO_META_BASE_DIR ${MESSAGE_DIR})
else()
file(MAKE_DIRECTORY ${MESSAGE_DIR})
SET(PROTO_META_BASE_DIR ${MESSAGE_DIR})
endif()
LIST(APPEND PROTO_FLAGS -I${CMAKE_SOURCE_DIR}/proto)
file(GLOB_RECURSE MSG_PROTOS ${CMAKE_SOURCE_DIR}/proto/*.proto)
set(MESSAGE_SRC "")
set(MESSAGE_HDRS "")
foreach(msg ${MSG_PROTOS})
get_filename_component(FIL_WE ${msg} NAME_WE)
list(APPEND MESSAGE_SRC "${CMAKE_SOURCE_DIR}/proto/${FIL_WE}.pb.cc")
list(APPEND MESSAGE_HDRS "${CMAKE_SOURCE_DIR}/proto/${FIL_WE}.pb.h")
add_custom_command(
OUTPUT "${CMAKE_SOURCE_DIR}/proto/${FIL_WE}.pb.cc"
"${CMAKE_SOURCE_DIR}/proto/${FIL_WE}.pb.h"
COMMAND ${PROTOBUF_PROTOC_EXECUTABLE}
ARGS --cpp_out=${PROTO_META_BASE_DIR} -I${CMAKE_SOURCE_DIR} ${msg}
DEPENDS ${msg}
COMMENT "Running C++ protocol buffer compiler on ${msg}"
VERBATIM
)
endforeach()
when i compile it , it turn out this error
[ 33%] Running C++ protocol buffer compiler on /home/dbn/work/seal/cmd/proto/test.proto
/bin/sh: -I/home/dbn/work/seal/cmd: No such file or directory
[ 66%] Running C++ protocol buffer compiler on /home/dbn/work/seal/cmd/proto/person.proto
/bin/sh: -I/home/dbn/work/seal/cmd: No such file or directory
[100%] generate message target
but actually ,the dir '/home/dbn/work/seal/cmd/proto' exist.
pwd
pwd
/home/dbn/work/seal/cmd
I have tried to ARGS --cpp_out=${PROTO_META_BASE_DIR} -I${CMAKE_SOURCE_DIR} ${msg}
to ARGS --cpp_out=${PROTO_META_BASE_DIR} -I=${CMAKE_SOURCE_DIR} ${msg}
but it's no use.
答案1
得分: 0
以下是翻译好的部分:
"the dir '/home/dbn/work/seal/cmd/proto' exist."
问题不在于不存在的目录'/home/dbn/work/seal/cmd/proto'。问题在于不存在的文件'-I/home/dbn/work/seal/cmd',这是shell试图运行为可执行文件的文件。这是由于空变量${PROTOBUF_PROTOC_EXECUTABLE}
引起的,而且显示的CMakeLists.txt可能不是您运行的内容。请检查您设置该变量的位置。
英文:
> the dir '/home/dbn/work/seal/cmd/proto' exist.
The issue is not the non existing directory /home/dbn/work/seal/cmd/proto
. The issue is the non existing file -I/home/dbn/work/seal/cmd
that the shell wants to run as an executable file. It happens because of the empty variable ${PROTOBUF_PROTOC_EXECUTABLE}
and the shown CMakeLists.txt is likely not what you run. Check where you setup the variable.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论