本文主要是介绍使用add_subdirectory构建glog和gflags的问题,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
问题描述
使用cmake构建项目,希望使用glog记录日志,但是glog默认依赖于gflags,所以将其作为子模块添加到主项目,代码如下:
add_subdirectory(../third_party/gflags)
add_subdirectory(../third_party/glog)
出现问题:
CMake Error: install(EXPORT "glog-targets" ...) includes target "glog" which requires target "gflags_nothreads_static" that is not in any export set.
CMake Error in D:/my/MiniNN/third_party/glog/CMakeLists.txt:export called with target "glog" which requires target"gflags_nothreads_static" that is not in this export set, but in multipleother export sets:D:/my/MiniNN/src/build/third_party/gflags/gflags-nonamespace-targets.cmake,D:/my/MiniNN/src/build/third_party/gflags/gflags-targets.cmake.An exported target cannot depend upon another target which is exportedmultiple times. Consider consolidating the exports of the"gflags_nothreads_static" target to a single export.
问题原因
实际是出现了2个导出集,chatgpt也没能给出一个可行的办法,上网查了查,很多讨论:
- https://github.com/google/glog/issues/198
- https://github.com/google/glog/issues/251
- https://github.com/google/glog/issues/381
- https://github.com/gflags/gflags/issues/279依然开启
- https://github.com/google/glog/issues/560
其中,单独编译glog不通过,因为依赖gtest,梳理好依赖之后,又依赖gflags,有点麻烦,再添加gflags,就出现了上面的问题,整的有点麻烦。
单独编译gflags,是可以编译通过的,gflags被当作子模块编译的时候,自己也提到了:
## When this project is a subproject (GFLAGS_IS_SUBPROJECT is TRUE), the default
## settings are such that only the static single-threaded library is built without
## installation of the gflags files. The "gflags::gflags" target is in this case an ALIAS
## library target for the "gflags_nothreads_static" library target. Targets which
## depend on the gflags library should link to the "gflags::gflags" library target.
问题解决
有以下几个方法供参考:
- 使用
ExternalProject
- 设置关闭gflags:
set(WITH_GFLAGS OFF)
add_subdirectory(../third_party/glog)
参考资料
以上链接
这篇关于使用add_subdirectory构建glog和gflags的问题的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!