Eigen cmake requires “target_link_libraries” even though it's template-only

梦想的初衷 提交于 2019-12-08 00:02:14

问题


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".

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

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.


回答1:


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.

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

Hope this helps other souls struggling with cmake!



来源:https://stackoverflow.com/questions/51887137/eigen-cmake-requires-target-link-libraries-even-though-its-template-only

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!