CMake Error: TARGETS given no LIBRARY DESTINATION for shared library target

戏子无情 提交于 2019-11-30 07:05:29

问题


When building an opensource project with CMake (in my case, it was the lemon graph library), I got this error when I tried to build shared libaries via -DBUILD_SHARED_LIBS=1:

TARGETS given no LIBRARY DESTINATION for shared library target

Where does this error come from and how do I fix it?


回答1:


In my CMakeLists.txt, my INSTALL command had no LIBRARY parameter.

Changing from this:

INSTALL(
  TARGETS lemon
  ARCHIVE DESTINATION lib
  COMPONENT library
)

to this:

INSTALL(
  TARGETS lemon
  ARCHIVE DESTINATION lib
  LIBRARY DESTINATION lib  # <-- Add this line
  COMPONENT library
)

fixed my problem.




回答2:


I got this... Another reason this happens is when you create a shared library

add_library(${NAME} SHARED sources )

then when Cmake reaches the install command on Windows platform, it complains of these error, solution is to use RUNTIME instead of LIBRARY, like

if(WIN32)
  install(TARGETS ${NAME}
    RUNTIME DESTINATION path)
else()
  install(TARGETS ${NAME}
    LIBRARY DESTINATION path)
endif()  



回答3:


After DESTINATION, it should have bin, lib, include.

install lib or 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
)

For example, install .h file:

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

see https://cmake.org/cmake/help/v3.0/command/install.html for more detail:

install(TARGETS myExe mySharedLib myStaticLib
        RUNTIME DESTINATION bin
        LIBRARY DESTINATION lib
        ARCHIVE DESTINATION lib/static)
install(TARGETS mySharedLib DESTINATION /some/full/path)


来源:https://stackoverflow.com/questions/14990343/cmake-error-targets-given-no-library-destination-for-shared-library-target

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