cmake add_library, followed by install library des

2019-06-17 08:06发布

问题:

I am trying to run cmake to generate makefiles. In the minimum working example, I have three files and 1 build directory.

File 1 is CMakeLists.txt, containing exactly:

add_library (MathFunctions SHARED mysqrt.cxx)
install (TARGETS MathFunctions LIBRARY DESTINATION lib)

File 2 is MathFunctions.h containing the function prototype, function relates to mysqrt.cxx.

File 3 is mysqrt.cxx containing include statement and a function definition.

When I create a build sub-directory and run "cmake ..", I am getting

CMake Error at CMakeLists.txt:2 (install):
  install Library TARGETS given no DESTINATION!

Isn't my add_library, then install statement grammar correct? If I remove both SHARED and LIBRARY, cmake builds without errors.

Thanks for your help.

回答1:

The problem is likely down to you running this on what CMake calls a "DLL platform" and how CMake classifies a shared library on such a platform.

From the docs for install:

For DLL platforms the DLL part of a shared library is treated as a RUNTIME target and the corresponding import library is treated as an ARCHIVE target. All Windows-based systems including Cygwin are DLL platforms.

So, try changing your command to something like:

install (TARGETS MathFunctions
         ARCHIVE DESTINATION lib
         LIBRARY DESTINATION lib
         RUNTIME DESTINATION bin)


标签: cmake