CMake 安装中的问题
- 错误
- 原因
- 解决
错误:
CMake Error at CMakeLists.txt:23 (INSTALL):
install TARGETS given target “hello” which does not exist in this
directory.
错误出处:
CMakeLists.txt中的
INSTALL(
TARGETS hello
RUNTIME DESTINATION bin
)
原因:
出现这一问题是因为,TARGETS 找不到生成对应的二进制或静态库或者动态库,目标对象。
如:
ADD_EXECUTABLE(hello main.cpp),其中的hello
就是TARGETS 的目标对象。
解决:
所以为了找到TARGETS 的目标对象,要保证语句
INSTALL( TARGETS hello RUNTIME DESTINATION bin)
在ADD_EXECUTABLE(hello main.cpp)之后即可。
(如果ADD_EXECUTABLE(hello main.cpp)在subdirectory的CMakeLists.txt中,则将install语句也放在subdirectory的CMakeLists.txt中的ADD_EXECUTABLE之后)