CMake的find_library找不到没有版本,扩展名和lib前缀的库

时间:2019-07-03 18:14:54

标签: cmake

当我拥有此CMakeLists.txt时,我正尝试链接至系统库I/art: Do partial code cache collection, code=26KB, data=29KB After code cache collection, code=25KB, data=28KB Increasing code cache capacity to 128KB D/Constraints: On Create View Holder: called D/Constraints: On Create View Holder: called D/Constraints: On Create View Holder: called V/FA: Inactivity, disconnecting from the service I/art: Do partial code cache collection, code=57KB, data=60KB I/art: After code cache collection, code=57KB, data=60KB Increasing code cache capacity to 256KB D/Constraints: recommended : Chili Paneer(Dry)

/usr/lib/x86_64-linux-gnu/libtcmalloc.so.4

(也尝试过cmake_minimum_required(VERSION 3.10 FATAL_ERROR) project(all) find_library(TCMALLOC_LIB NAMES tcmalloc) if(TCMALLOC_LIB) message("Found TCMALLOC_LIB: ${TCMALLOC_LIB}") else() message(FATAL_ERROR "TCMALLOC_LIB library not found") endif()

我明白了

find_library(TCMALLOC_LIB tcmalloc)

如果有的话

CMake Error at CMakeLists.txt:13 (message):
  TCMALLOC_LIB library not found

一切都很好:find_library(TCMALLOC_LIB NAMES libtcmalloc.so.4)

我做错什么了吗?为什么需要精确指定文件名?如何调试Found TCMALLOC_LIB: /usr/lib/x86_64-linux-gnu/libtcmalloc.so.4

1 个答案:

答案 0 :(得分:1)

更新-真正原因

正如@Tsyvarev在评论中提到的,事实证明cmake找不到该库,因为我只是“部分”安装了该库,因此应该已经安装了-dev版本(libgoogle-perftools-dev)。 / p>


TL; DR

好吧,事实证明tcmalloc不是常规/常规库,也就是说,它没有指向libtcmalloc.so的{​​{1}}符号链接,这就是cmake找不到它的原因。

如何调试.so.4

我找到了一种通过find_library调试find_library的方法:

strace

从此$ rm -rf ./* && strace cmake ../scripts/ 2>&1 | grep tcmalloc access("/usr/local/nvidia/bin/libtcmalloc.so", R_OK) = -1 ENOENT (No such file or directory) access("/usr/local/cuda/bin/libtcmalloc.so", R_OK) = -1 ENOENT (No such file or directory) access("/usr/local/sbin/libtcmalloc.so", R_OK) = -1 ENOENT (No such file or directory) access("/usr/local/bin/libtcmalloc.so", R_OK) = -1 ENOENT (No such file or directory) ... <many lines skipped> ... 输出中,我们看到该cmake,实际上是尝试strace之前并附加lib,但它没有尝试在任何版本之前。

现在,如果我们看另一个“普通”库:

.so

我们将看到它确实安装了# locate protobuf | grep "\.so" /usr/lib/x86_64-linux-gnu/libprotobuf.so /usr/lib/x86_64-linux-gnu/libprotobuf.so.17 /usr/lib/x86_64-linux-gnu/libprotobuf.so.17.0.0 符号链接,而.so没有安装:

tcmalloc