当建立与CMake的一个开源项目(对我来说,这是柠檬图形库),我得到这个错误,当我试图通过建立共享libaries -DBUILD_SHARED_LIBS=1
:
TARGETS given no LIBRARY DESTINATION for shared library target
哪里是从哪里来的这个错误,我该如何解决?
当建立与CMake的一个开源项目(对我来说,这是柠檬图形库),我得到这个错误,当我试图通过建立共享libaries -DBUILD_SHARED_LIBS=1
:
TARGETS given no LIBRARY DESTINATION for shared library target
哪里是从哪里来的这个错误,我该如何解决?
在我CMakeLists.txt
,我的安装命令没有LIBRARY参数。
从这个改变:
INSTALL(
TARGETS lemon
ARCHIVE DESTINATION lib
COMPONENT library
)
为此:
INSTALL(
TARGETS lemon
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib # <-- Add this line
COMPONENT library
)
固定我的问题。
我得到这个......出现这种情况的另一个原因是,当你创建一个共享库
add_library($ {NAME} SHARED源)
那么当CMake的到达在Windows平台上安装命令,它抱怨这些错误的,解决方法是使用运行时,而不是图书馆,像
if(WIN32)
install(TARGETS ${NAME}
RUNTIME DESTINATION path)
else()
install(TARGETS ${NAME}
LIBRARY DESTINATION path)
endif()
之后DESTINATION
,它应该有bin
, lib
, include
。
安装lib
或bin
install(TARGETS snappy
EXPORT SnappyTargets
# RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} # DESTINATION error
RUNTIME DESTINATION bin ${CMAKE_INSTALL_BINDIR} # should add bin or other dir
LIBRARY DESTINATION lib ${CMAKE_INSTALL_LIBDIR}
# ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR # DESTINATION error
ARCHIVE DESTINATION lib ${CMAKE_INSTALL_LIBDIR} # should add lib
)
例如,安装.h
文件:
install(
FILES
"${PROJECT_SOURCE_DIR}/test_hard1.h"
"${PROJECT_BINARY_DIR}/config.h"
# DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} # error install FILES given no DESTINATION!
# add include after DESTINATION, then it works
DESTINATION include ${CMAKE_INSTALL_INCLUDEDIR}
)
看到https://cmake.org/cmake/help/v3.0/command/install.html更多的细节:
install(TARGETS myExe mySharedLib myStaticLib
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib/static)
install(TARGETS mySharedLib DESTINATION /some/full/path)