How does Eigen work as a header-only library?
Asked Answered
O

0

6

Recently I am using Eigen library for a project. I’m curious why there’s no binary file to link, but only a header. I don’t really understand how Eigen works behind the scene to make this possible.

Oriente answered 1/12, 2018 at 19:11 Comment(5)
Read the source code - it's all in the headersFollowing
@Following Right, I just found out. But why is it still necessary to link Eigen library when working with CMake?Oriente
CMake linking is not the exact same as linking a precompiled library. Eigen provides a "library target" for CMake which you are linking, but this does not mean you are linking to a binaryFollowing
@Following Really appreciate your explanation! I also found a related thread here: https://mcmap.net/q/1919016/-eigen-cmake-requires-quot-target_link_libraries-quot-even-though-it-39-s-template-only . I am now reading to learn more about the mechanism.Oriente
Not sure what your question is actually about. Header-only libraries generally "work" by having every function inline (explicitly or implicitly). If this is about how this affects building with CMake, state that in your question more clearly (ideally showing a problem which you have).Thuthucydides

© 2022 - 2024 — McMap. All rights reserved.