开发者

Compiling libraries with CMake under Cygwin

开发者 https://www.devze.com 2023-01-17 05:02 出处:网络
I have been trying to compile TinyXML usin开发者_Go百科g 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

I have been trying to compile TinyXML usin开发者_Go百科g 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?


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.


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

精彩评论

暂无评论...
验证码 换一张
取 消