cmake build protobuf error: NMAKE : fatal error U1073: don't know how to make 'PROTOBUF_PROTOC_EXECUTABLE-NOTFOUND'
cmake build protobuf error: NMAKE : fatal error U1073: don't know how to make 'PROTOBUF_PROTOC_EXECUTABLE-NOTFOUND'
这是我的项目树:
proto-build
|—— build/ #empty, used for cmake building
|—— include/
|—— google/ #protobuf headers
|—— lib/
|—— libprotobuf-lite.lib
|—— proto/
|—— test.proto
|—— CMakeLists.txt
这是 CMakeLists.txt:
cmake_minimum_required(VERSION 3.5)
set(CMAKE_VERBOSE_MAKEFILE ON)
SET(ROOT_PATH ".")
SET(PROTO_DIR ${ROOT_PATH}/proto)
SET(PROTOBUF_LIBRARY ${ROOT_PATH}/lib)
SET(PROTOBUF_INCLUDE_DIR ${ROOT_PATH}/include)
find_package(Protobuf REQUIRED)
protobuf_generate_cpp(PROTO_SRCS PROTO_HDRS ${PROTO_DIR}/test.proto)
add_library(foo ${PROTO_SRCS} ${PROTO_HDRS})
target_link_libraries(foo ${PROTOBUF_LIBRARIES})
然后我打开cmd并定位到proto-build/build/, 运行 command:
cmake -G"NMake Makefiles" -DCMAKE_BUILD_TYPE=Release ..
它工作正常。然后 运行 命令:
nmake
发生错误:
NMAKE : fatal error U1073: don't know how to make 'E:\Source\proto-build\PROTOBUF_PROTOC_EXECUTABLE-NOTFOUND'
Stop.
NMAKE : fatal error U1077: '"D:\Program_Filesx86\Microsoft Visual Studio 14.0\VC\BIN\amd64\nmake.exe"' : return code '0x2'
Stop.
NMAKE : fatal error U1077: '"D:\Program_Filesx86\Microsoft Visual Studio 14.0\VC\BIN\amd64\nmake.exe"' : return code '0x2'
Stop.
未找到 Protobuf 可执行文件。这个错误的路径 E:\Source\proto-build\PROTOBUF_PROTOC_EXECUTABLE-NOTFOUND
被写入 Makefile 并且这个错误出来了。
感谢 usr1234567 的建议,我已经弄明白了,这是新的 CMakeLists.txt:
cmake_minimum_required(VERSION 3.5)
set(CMAKE_VERBOSE_MAKEFILE ON)
SET(ROOT_PATH ".")
SET(PROTO_DIR ${ROOT_PATH}/proto)
#must define these tow variables:PROTOBUF_INCLUDE_DIR & PROTOBUF_LIBRARY, even the value is invalid.
SET(PROTOBUF_INCLUDE_DIR .)
SET(PROTOBUF_LIBRARY .)
SET(PROTOBUF_PROTOC_EXECUTABLE ../protoc.exe)
#in this directory, contains protobuf includes: top directory is <google>
SET(THIRD_INCLUDE_DIR ${ROOT_PATH}/include)
#if set PROTOBUF_INCLUDE_DIR to the directory of protobuf includes instead of using include_directories, errors occurred when nmake,I don't know why
include_directories(${THIRD_INCLUDE_DIR})
file(GLOB PROTO_LIST ${PROTO_DIR}/*.proto)
find_package(Protobuf REQUIRED)
protobuf_generate_cpp(PROTO_SRCS PROTO_HDRS ${PROTO_LIST})
add_library(foo ${PROTO_SRCS} ${PROTO_HDRS})
target_link_libraries(foo)
用这个CMakeLists.txt来camke和nmake,编译成功。
有几个细节需要注意,我在CMakeLists.txt.
评论
有一个奇怪的问题:你必须在 directory:one 中放置两个 protoc.exe 文件,一个在 proto-build/ 中,一个不在 proto- build/, 否则会报错: not found protoc.exe.
这是我的项目树:
proto-build
|—— build/ #empty, used for cmake building
|—— include/
|—— google/ #protobuf headers
|—— lib/
|—— libprotobuf-lite.lib
|—— proto/
|—— test.proto
|—— CMakeLists.txt
这是 CMakeLists.txt:
cmake_minimum_required(VERSION 3.5)
set(CMAKE_VERBOSE_MAKEFILE ON)
SET(ROOT_PATH ".")
SET(PROTO_DIR ${ROOT_PATH}/proto)
SET(PROTOBUF_LIBRARY ${ROOT_PATH}/lib)
SET(PROTOBUF_INCLUDE_DIR ${ROOT_PATH}/include)
find_package(Protobuf REQUIRED)
protobuf_generate_cpp(PROTO_SRCS PROTO_HDRS ${PROTO_DIR}/test.proto)
add_library(foo ${PROTO_SRCS} ${PROTO_HDRS})
target_link_libraries(foo ${PROTOBUF_LIBRARIES})
然后我打开cmd并定位到proto-build/build/, 运行 command:
cmake -G"NMake Makefiles" -DCMAKE_BUILD_TYPE=Release ..
它工作正常。然后 运行 命令:
nmake
发生错误:
NMAKE : fatal error U1073: don't know how to make 'E:\Source\proto-build\PROTOBUF_PROTOC_EXECUTABLE-NOTFOUND'
Stop.
NMAKE : fatal error U1077: '"D:\Program_Filesx86\Microsoft Visual Studio 14.0\VC\BIN\amd64\nmake.exe"' : return code '0x2'
Stop.
NMAKE : fatal error U1077: '"D:\Program_Filesx86\Microsoft Visual Studio 14.0\VC\BIN\amd64\nmake.exe"' : return code '0x2'
Stop.
未找到 Protobuf 可执行文件。这个错误的路径 E:\Source\proto-build\PROTOBUF_PROTOC_EXECUTABLE-NOTFOUND
被写入 Makefile 并且这个错误出来了。
感谢 usr1234567 的建议,我已经弄明白了,这是新的 CMakeLists.txt:
cmake_minimum_required(VERSION 3.5)
set(CMAKE_VERBOSE_MAKEFILE ON)
SET(ROOT_PATH ".")
SET(PROTO_DIR ${ROOT_PATH}/proto)
#must define these tow variables:PROTOBUF_INCLUDE_DIR & PROTOBUF_LIBRARY, even the value is invalid.
SET(PROTOBUF_INCLUDE_DIR .)
SET(PROTOBUF_LIBRARY .)
SET(PROTOBUF_PROTOC_EXECUTABLE ../protoc.exe)
#in this directory, contains protobuf includes: top directory is <google>
SET(THIRD_INCLUDE_DIR ${ROOT_PATH}/include)
#if set PROTOBUF_INCLUDE_DIR to the directory of protobuf includes instead of using include_directories, errors occurred when nmake,I don't know why
include_directories(${THIRD_INCLUDE_DIR})
file(GLOB PROTO_LIST ${PROTO_DIR}/*.proto)
find_package(Protobuf REQUIRED)
protobuf_generate_cpp(PROTO_SRCS PROTO_HDRS ${PROTO_LIST})
add_library(foo ${PROTO_SRCS} ${PROTO_HDRS})
target_link_libraries(foo)
用这个CMakeLists.txt来camke和nmake,编译成功。 有几个细节需要注意,我在CMakeLists.txt.
评论有一个奇怪的问题:你必须在 directory:one 中放置两个 protoc.exe 文件,一个在 proto-build/ 中,一个不在 proto- build/, 否则会报错: not found protoc.exe.