在Cygwin下使用CMake编译库 [英] Compiling libraries with CMake under Cygwin

查看:713
本文介绍了在Cygwin下使用CMake编译库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试使用CMake编译TinyXML,这是一种小型项目,试图学习CMake.另外,我试图将其编译为动态库并进行自我安装,使其能够正常工作.

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.

到目前为止,我已经设法将其编译并安装,但是将其编译为.dll和.dll.a,使其正常工作的唯一方法是将其安装到/bin和/lib中,这样就可以将两个文件都安装在两个文件夹中.此安装程序有效,但我猜测.dll应该位于/bin中,而.dll.a应该位于/lib中.这是特定于Cygwin的问题,还是我做错了什么?

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?

推荐答案

.dll是运行时库文件,该文件必须在运行时出现在目标系统上(并在其中的$ PATH中). .dll.a文件是.dll的导入库,在链接时该文件必须存在于编译机上.您需要将.dll文件分发到程序应运行的位置,并将.dll和.dll.a都分发到使用该库链接其他程序的位置.您只需要在运行该程序的计算机上不需要.dll.a文件即可.

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.

这篇关于在Cygwin下使用CMake编译库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆