问题描述
在Eigen库的中,它需要以下行:$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问题中的讨论相矛盾:
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.
参考文献:
-
-
希望这可以帮助其他挣扎cmake的人!
Hope this helps other souls struggling with cmake!
这篇关于本征cmake要求使用“ target_link_libraries”即使仅模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!