CMake Error at CMakeLists.txt:24

当遇到CMake Error at CMakeLists.txt:24 (add_subdirectory): add_subdirectory给出的源gtest目录不存在的问题时,原因在于Cmake版本低于3.11不支持没有源文件的add_library。从Cmake 3.11开始,add_library和add_executable命令即使没有源文件也不会报错,只要后续通过target_sources()添加源文件即可。解决方案是创建一个名为'empty.cpp'的文件,并修改flann/src/cpp/CMakeLists.txt中的相应行,将add_library的源文件替换为'empty.cpp'。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

问题:CMake Error at CMakeLists.txt:24 (add_subdirectory):
add_subdirectory given source "gtest" which is not an existing directory.

解答:

Cmake < 3.11 doesn't support add_library without any source file, but flann CMake use a trick that use an empty string "" as source list (i.e add_library(foo SHARED "")).
The existing flann Cmake code violates the new behavior of add_library() for Cmake>=3.11.
buildroot/buildroot@45a39b3

It turns out in Cmake 3.11, "add_library()" and "add_executable()" commands can be called without any sources and won't complain as long as sources are added later via "target_sources()" command.
https://blog.kitware.com/cmake-3-11-0-available-for-download/

Fix is proposed here:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值