本征cmake要求使用“ target_link_libraries”即使仅模板 [英] Eigen cmake requires "target_link_libraries" even though it's template-only

查看:207
本文介绍了本征cmake要求使用“ target_link_libraries”即使仅模板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Eigen库的官方cmake文档中,它需要以下行:$code> target_link_libraries(例如Eigen3 :: Eigen)。我尝试删除该行,但是随后编译将失败,并显示未找到本征。

In Eigen library's official cmake doc, it requires the line target_link_libraries (example Eigen3::Eigen). I have tried removing that line, but then the compilation would fail with "Eigen not found".

这直接与另一个StackOverflow问题中的讨论相矛盾:在我的Cmake项目中使用Eigen Lib吗?

This directly contradicts the discussion in another StackOverflow question: Using Eigen Lib in my Cmake project?

我不明白为什么Eigen需要 target_link_libraries 即使是仅模板的库?就像上面的StackOverflow问题一样,我假设我只需要包含Eigen标头( include_directories()),它就可以直接使用。没错

I don't understand why Eigen would need target_link_libraries even though it's a template-only library? Just like the above StackOverflow question, I'd assume I only have to include the Eigen headers (include_directories()) and it should work out of the box. It doesn't.

推荐答案

啊,我现在知道发生了什么:CMake中有一个称为接口库的概念实际上并没有建立一个库二进制文件。它是专为像Eigen这样的仅模板库而设计的。

Ah now I know what's going on: there's a concept called "interface library" in CMake that doesn't actually build a library binary. It is designed precisely for template-only libraries like Eigen.

参考文献:
- https://cmake.org/cmake/help/latest/command/add_library.html#interface-libraries
- http://mariobadr.com/creating-a-header-only-library-with-cmake.html

希望这可以帮助其他挣扎cmake的人!

Hope this helps other souls struggling with cmake!

这篇关于本征cmake要求使用“ target_link_libraries”即使仅模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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