Compiling libraries with CMake under Cygwin

那年仲夏 提交于 2019-12-12 18:18:18

问题


I have been trying to compile TinyXML using CMake as a sort of mini project, trying to learn CMake. As an addition I am trying to make it compile into a dynamic library and install itself so it works.

So far I have managed to get it to compile and install BUT it compiles into a .dll and a .dll.a and the only way to get it to work is to have it install into both /bin and /lib, which makes it install both files in both folders. This setup works but I'm guessing the .dll should be in /bin and the .dll.a should be in /lib. Is this some sort of Cygwin-specific problem or am I doing something wrong?


回答1:


The .dll is the runtime library file, which must be present on the target system on run time (and be in $PATH there). The .dll.a file is the import library for the .dll, which must be present on the compiling machine at link time. You need to distribute the .dll file to the places where the program should run, and both .dll and .dll.a to places where the library is used to link other programs. you don't need the .dll.a file on the machines running the program only.

When you don't want to create a shared library, you can tell this to cmake with the static keyword in the add_library command:

add_library(mylib STATIC foo.c bar.cpp)

This way there will no shared library created, but the code from the library will be added by the linker into the final executable file.




回答2:


What you need is to specify a destination for each type of file.

The .dll is considered a RUNTIME library and the .a is an ARCHIVE. Just in case, for other platforms, you probably want the LIBRARY entry (for .so files).

install( TARGETS ${PROJECT_NAME}
  LIBRARY DESTINATION lib
  ARCHIVE DESTINATION lib
  RUNTIME DESTINATION bin
)


来源:https://stackoverflow.com/questions/3763212/compiling-libraries-with-cmake-under-cygwin

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