CMake是否需要静态库(例如ZLIB)? [英] Can CMake require static libraries (e.g., ZLIB)?

查看:541
本文介绍了CMake是否需要静态库(例如ZLIB)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 C ++ 工作已经有好几年了,而我以前从未使用过 CMake 。我正在尝试编译一个名为 ngmlr 的程序,该程序使用 CMake 。它在我尝试构建的其他系统上无缝运行。这次, CMake 查找 ZLIB 找到ZLIB:/ usr / lib64 / libz。因此(找到版本 1.2.3)),这是 ngmlr 所要求的,但随后的 make 失败,出现 ld:找不到-lz

It has been years since I worked in C++, and I've never used CMake before. I'm trying to compile a program called ngmlr, which uses CMake. It worked seamlessly on other systems I tried to build it on. This time around, CMake finds ZLIB (Found ZLIB: /usr/lib64/libz.so (found version "1.2.3")), as required by ngmlr, but the subsequent make fails with ld: cannot find -lz.

思考我知道这是怎么回事: CMake 找到了动态的 ZLIB 库( libz.so ),但 CMakeLists.txt 文件需要 static (我在文件中找到以下选项: 选项(静态建立静态二进制文件为开))。据我所知,此计算机上缺少静态库( libz.a )。它与 libz.so 不在同一个 / usr / lib64 目录中。 locate 不可用。

I think I know what's happening: CMake found the dynamic ZLIB library (libz.so), but the CMakeLists.txt file requires static (I found the following option in the file: option(STATIC "Build static binary" ON)). As far as I can tell, the static library (libz.a) is missing on this machine. It's not in the same /usr/lib64 directory as libz.so. locate is not available.

问题:


  1. 看起来正确吗?

  2. 对于教育,假设这是问题所在,您可以强制将 CMake 设置为专门针对静态 ZLIB ?例如,由于开发人员需要 static ,很高兴能立即知道缺少的 static 库是问题所在,而不是花了我很长时间才能解决的令人尴尬的时间。

  1. Does that seem correct?
  2. For education, assuming this is the problem, can you force CMake to look specifically for static ZLIB? e.g., since the developer required static, it would have been nice to immediately know the missing static library was the problem, rather than the embarrassingly long amount of time it took me to figure it out.

,但没有确定的结论(例如,强制cmake使用静态库)。

I've looked extensively for a clear answer to both, but didn't find anything conclusive (e.g., Force cmake to use static libraries).

更新
我确实确认问题是 ld 找不到静态库。现在,我特别想知道如果 static 库不是,开发人员是否可以告诉 CMake 引发错误。目前,并保存其他人。

UPDATE I did confirm that the problem is that ld could not find the static library. Now I'm particularly interested to know if the developer can tell CMake to throw an error if the static libraries are not present, and save someone else.

cmake版本2.8.8

推荐答案



  1. 通常来说,这取决于查找模块的作者。一些模块具有特殊的静态选项,而其他模块则没有。特别是 Zlib 模块没有。因此,在子目录 src / CMakeLists.txt SET(CMAKE_FIND_LIBRARY_SUFFIXES .a)中设置cmake全局变量。但是它是在 find_package(需要ZLIB)命令之后调用的。看起来像个错误。

  1. Yes
  2. Generally speaking it is up to Find-module authors. Some modules have special "static" option, others do not. Particularly Zlib module has not. That's why cmake global variable is set in subdirectory src/CMakeLists.txt: SET(CMAKE_FIND_LIBRARY_SUFFIXES ".a"). But it is invoked after find_package( ZLIB REQUIRED ) command. Looks like a bug.




现在,我特别想知道开发人员是否可以告诉CMake如果不存在静态库,则抛出错误并保存其他人。

Now I'm particularly interested to know if the developer can tell CMake to throw an error if the static libraries are not present, and save someone else.

需要表示如果未找到软件包,将引发错误。在您的情况下,如果在 find_package

REQUIRED means that error will be thrown if package was not found. In your case it should be thrown if you move SET(CMAKE_FIND_LIBRARY_SUFFIXES before find_package

如果禁用 STATIC 选项

cmake -G"Unix Makefiles" _PATH_ -DSTATIC=OFF

这篇关于CMake是否需要静态库(例如ZLIB)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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