CMake error “Can not find target to add properties to”

匿名 (未验证) 提交于 2019-12-03 01:18:02

问题:

In my CMakeLIsts.txt file I write this:

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

When I run cmake, it shows the error message:

set_target_properties Can not find target to add properties to: hello_static 

回答1:

For your code to work, hello_static must be the name of a CMake target; something which is added via the add_executable or add_library commands for example.

This is unrelated to the name of your project.

It looks like you're missing something like:

add_library(hello_static ${LIBHELLO_SRC}) 

which would be placed immediately after

set(LIBHELLO_SRC hello.c) 


回答2:

Try this:

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

This works for me.

But if you just want a "hello" executable. you can reduced this to:

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


标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!