conan: [bug] transitive-libs=false shared library do not link on sysroot profiles
Describe the bug
If A depends on a shared library B and A says that B is not a transitive libs, the GCC linker command fails when using shared libraries and using sysroot.
If I then set B as being a transitive-libs the whole things works.
What I see is that the target_data.cmake file has a diff:
32c32
< set(B_LIBS_RELWITHDEBINFO B)
---
> set(B_LIBS_RELWITHDEBINFO )
64c64
< set(B_B_B_LIBS_RELWITHDEBINFO B)
---
> set(B_B_B_LIBS_RELWITHDEBINFO )
at the link.txt generated by cmake we see this convert in the lib being added to the command or not.
When we do not specify the lib, the behavior of the linker is then to search for the library using rpath and others, except that gcc will “prepend” the sysroot to any specified rpaths. Since conan install will install the deps in the .conan2/p folder, the rpath cannot work with GCC (GCC always prepend the sysroot to any rpath).
When we set transitive-libs we see the lib B added to the linker command and things works.
I believe the code in conan that cause the diff is:
# traits logic
if require and not require.headers:
self.include_paths = ""
if require and not require.libs:
# self.lib_paths = "" IMPORTANT! LINKERS IN LINUX FOR SHARED MIGHT NEED IT EVEN IF
# NOT REALLY LINKING LIB
self.libs = ""
if cpp_info.frameworkdirs: # Only invalidate for in-package frameworks
# FIXME: The mix of in-package frameworks + system ones is broken
self.frameworks = ""
inside conan/tools/cmake/cmakedeps/template/target_data.py
I need to understand why the transitive_libs set to false require that the linker use the search path instead of having the lib explicitly pass as it is done with transitive_libs set to true.
It also seems that when using GCC, conan/cmake should be using -Wl,-rpath-link instead of -Wl,-rpath, since conan will never copy the package file in the sysroot.
How to reproduce it
Create a shared lib as B Create a shared lib as A Have A depends on B target_link_libraries(A PRIVATE B)
If B is transitive-libs = true, it works, it B is transitive_libs = false it fails
Only in cross-compilation with gcc.
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 21 (9 by maintainers)
But that is not an error, just a warning. It is the auto-detection of the location of the artifact. We might try to improve the code, but it is also already possible to define the
cpp_info.locationinformation in thegrpclibrary to dissambiguate.It would be good to have this reported as its own ticket, with details on how to reproduce, @franramirez688 developed the auto-detection, he might try to add this case too.