Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid calling target_link_libraries to Eigen3, since it is a header-only library #175

Closed
evan-flynn-apexai opened this issue Nov 13, 2024 · 3 comments

Comments

@evan-flynn-apexai
Copy link

evan-flynn-apexai commented Nov 13, 2024

Today osqp-eigen calls target_link_libraries to Eigen3. Eigen3 is a header-only library, so this should not be needed and instead just include the Eigen3 directories.

https://stackoverflow.com/questions/28267104/using-eigen-lib-in-my-cmake-project

By calling target_link_libraries to Eigen3, it means the Eigen3 symbols are included in the generated osqp_eigen .so file....which it probably should not since it makes the generated .so files much hard to relocate on different systems

@traversaro
Copy link
Member

Today osqp-eigen calls target_link_libraries to Eigen3. Eigen3 is a header-only library, so this should not be needed and instead just include the Eigen3 directories.

Eigen::Eigen3 is a CMake INTERFACE imported target, see the definition in Eigen3Targets.cmake:

add_library(Eigen3::Eigen INTERFACE IMPORTED)

set_target_properties(Eigen3::Eigen PROPERTIES
  INTERFACE_INCLUDE_DIRECTORIES "${_IMPORT_PREFIX}/include/eigen3"
)

so linking it via target_include_directories has the exact effect of just adding the Eigen3's include directory to the compiler invocation for all the compilation units of the linked library. That is exactly like calling target_include_directories with Eigen3's include dirs, with the additional advantage that if Eigen3 is used in the public headers of the libraries (i.e. with PUBLIC keyword) the resulting CMake config files is relocatable, while it would be non-relocatable if you hardcoded the location of Eigen3 directories via target_include_directories (see the first example in https://cmake.org/cmake/help/latest/manual/cmake-packages.7.html#creating-relocatable-packages).

https://stackoverflow.com/questions/28267104/using-eigen-lib-in-my-cmake-project

This is a really old SO answers, that I guess predates when the Eigen3::Eigen imported targets was introduced in Eigen. See the official Eigen documentation on the suggested way of consuming Eigen3 in CMake projects: https://eigen.tuxfamily.org/dox/TopicCMakeGuide.html .

By calling target_link_libraries to Eigen3, it means the Eigen3 symbols are included in the generated osqp_eigen .so file....which it probably should not since it makes the generated .so files much hard to relocate on different systems

I am not sure I follow what you mean with this sentence. How is the current .so hard to relocate on different systems? To avoid the XY problem (https://en.wikipedia.org/wiki/XY_problem) probably it could be useful if you explain the error or problem you are experiencing with osqp-eigen ?

@evan-flynn-apexai
Copy link
Author

@traversaro guess you are correct! this is then not the issue I'm seeing. Thanks for the help 🙏

@traversaro
Copy link
Member

@traversaro guess you are correct! this is then not the issue I'm seeing. Thanks for the help 🙏

No problem! Feel free to share more details on the issues you are seeing. Indeed, when Eigen is used as a private dependencies sometimes it is better not to use target_link_libraries (see robotology/idyntree#1065) but that is not the case with osqp-eigen.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants