2013-02-27 131 views
3

在我的CMakeLists.txt文件,我写这篇文章:cmake的编译错误

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无法找到目标将属性添加到: hello_static

+0

之后放置也许你的目标名称或路径是错误的或尚未建立。 – Erfankam 2017-02-27 12:19:31

回答

5

为您的代码工作,hello_static必须是CMake的目标的名称;例如,通过add_executableadd_library命令添加的东西。

这与您的项目名称无关。

它看起来像你失去了一些东西,如:

add_library(hello_static ${LIBHELLO_SRC}) 

这将立即

set(LIBHELLO_SRC hello.c) 
+0

哦,它真的很有用,非常感谢 – CharlesX 2013-02-28 02:24:46

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}) 

这对我的作品。

但是,如果你只是想要一个“你好”的可执行文件。你可以减少这:

project(hello_static) 
set(LIBHELLO_SRC hello.c) 
add_executable(hello ${LIBHELLO_SRC}) 
+0

你的意思是我应该确保我的项目名称是hello_static? – CharlesX 2013-02-27 11:06:11

+0

是的。这是最简单的,如果这是你想要做的。 – Lars 2013-02-27 11:08:52

+0

我已将项目名称更改为hello_static,但它不起作用 – CharlesX 2013-02-27 11:10:10