Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 426
Stuart Berg Avatar asked Feb 20 '13 21:02

Stuart Berg


3 Answers

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.

like image 73
Stuart Berg Avatar answered Oct 28 '22 07:10

Stuart Berg


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()  
like image 25
Fernando Gonzalez Sanchez Avatar answered Oct 28 '22 05:10

Fernando Gonzalez Sanchez


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)
like image 5
Jayhello Avatar answered Oct 28 '22 06:10

Jayhello