Cmake add_library and then the installation address of the installation library

I am trying to run cmake to create makefiles. In a minimal 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 prototype of the function; the function refers to mysqrt.cxx.

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

When I create a subdirectory of the assembly and run "cmake ..", I get

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

Isn't that my add_library, but the correct grammar setting? If I delete both SHARED and LIBRARY, cmake builds without errors.

Thank you for your help.

+6
source share
1 answer

The problem is probably due to the fact that you are running this on what CMake calls the "platform DLL" and how CMake classifies the shared library on that platform.

From the docs for install :

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

So try changing the command to something like:

 install (TARGETS MathFunctions ARCHIVE DESTINATION lib LIBRARY DESTINATION lib RUNTIME DESTINATION bin) 
+11
source

All Articles