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

[develop2] fixing transitive linux libraries cmake #13010

Merged

Conversation

memsharded
Copy link
Member

@memsharded memsharded commented Jan 30, 2023

Changelog: Fix: Fixing transitive shared linux libraries in CMakeDeps.

Close #13000

There were an issue where building against transitive shared dependencies in Linux (several transitive levels), was failing when this happens in different machines (need to upload & install in a different machine to reproduce), because the linker wants information about the libs, even if not strictly necessary to the final consumer application.

The approach that seems to work is:

  • Add INTERFACE_LINK_DIRECTORIES to each target creation
  • Make sure that the traits in CMakeDeps do not invalidate self.lib_paths, only libs to still avoiding direct linking.

This might need to extend to components too.

@memsharded memsharded added this to the 2.0.0-beta9 milestone Jan 30, 2023
@memsharded memsharded requested a review from jcar87 January 30, 2023 18:24
@@ -108,6 +108,10 @@ def template(self):
set_property(TARGET {{root_target_name}}
PROPERTY INTERFACE_INCLUDE_DIRECTORIES
$<$<CONFIG:{{configuration}}>:${{'{'}}{{pkg_name}}_INCLUDE_DIRS{{config_suffix}}}> APPEND)
# Necessary to find LINK shared libraries in Linux
set_property(TARGET {{root_target_name}}
PROPERTY INTERFACE_LINK_DIRECTORIES
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a bit confused - I think this would only solve the problem in some cases, but not all.

If the INTERFACE_LINK_DIRECTORIES property eventually maps to cmake passing -L entries to the. linker, the linker documentation (https://linux.die.net/man/1/ld) for -L states that these only apply to libraries linked via -l. This is relevant since the linker will not search in -L directories for "indirect" transitive runtime dependencies that are also not expressed in the linker flags.

That's what -rpath or -rpath-link achieves that -L doesn't (-rpath works ok when not cross building, -rpath-link is needed when a sysroot is also passed).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The command for creating app in my test is:

/usr/bin/cmake -E cmake_link_script CMakeFiles/app.dir/link.txt --verbose=1
/usr/bin/g++ -m64 -O3 -DNDEBUG -m64 CMakeFiles/app.dir/src/app.cpp.o -o app   -L"/tmp/tmpbiy1ou19conans/path with spaces/.conan2/p/31071b4017b74cd1/p/lib"  -L"/tmp/tmpbiy1ou19conans/path with spaces/.conan2/p/bbd4a1e27c1d25cc/p/lib" 

 -Wl,-rpath,"/tmp/tmpbiy1ou19conans/path with spaces/.conan2/p/31071b4017b74cd1/p/lib:/tmp/tmpbiy1ou19conans/path with spaces/.conan2/p/bbd4a1e27c1d25cc/p/lib" 

"/tmp/tmpbiy1ou19conans/path with spaces/.conan2/p/31071b4017b74cd1/p/lib/libchat.so"

I have isolated the -Wl, -rpath line, that contains 2 entries, for chat and hello.

@memsharded memsharded marked this pull request as ready for review January 30, 2023 23:53
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

Successfully merging this pull request may close these issues.

3 participants