7

在我的 CMakeLIsts.txt 文件中,我这样写:

set(LIBHELLO_SRC hello.c)
set_target_properties(hello_static PROPERTIES OUTPUT_NAME "hello")
get_target_property(OUTPUT_VALUE hello_static OUTPUT_NAME)
message(STATUS "This is the hello_static OUTPUT_NAME:"${OUTPUT_VALUE})

当我运行时cmake,它显示错误消息:

set_target_properties Can not find target to add properties to: hello_static
4

2 回答 2

11

要使您的代码正常工作,hello_static 必须是 CMake 目标的名称;例如通过add_executableor命令添加的东西。add_library

这与您的项目名称无关。

看起来您缺少以下内容:

add_library(hello_static ${LIBHELLO_SRC})

这将立即放置在

set(LIBHELLO_SRC hello.c)
于 2013-02-27T13:40:11.060 回答
0

试试这个:

project(hello_static)
set(LIBHELLO_SRC hello.c)
add_executable(hello_static ${LIBHELLO_SRC})
set_target_properties(hello_static PROPERTIES OUTPUT_NAME "hello")
get_target_property(OUTPUT_VALUE hello_static OUTPUT_NAME)
message(STATUS "This is the hello_static OUTPUT_NAME:"${OUTPUT_VALUE})

这对我有用。

但是,如果您只想要一个“hello”可执行文件。您可以将其简化为:

project(hello_static)
set(LIBHELLO_SRC hello.c)
add_executable(hello ${LIBHELLO_SRC})
于 2013-02-27T11:03:39.657 回答