conan-io / conan-center-index

Recipes for the ConanCenter repository
https://conan.io/center
MIT License
945 stars 1.71k forks source link

[package] grpc/1.65.0: downstream builds break if absel is used as shared #24806

Closed weatherhead99 closed 1 week ago

weatherhead99 commented 1 month ago

Description

When building a package which depends on gRPC, and using abseil as a shared library, downstream builds can break with an error like (on gcc):

undefined reference to symbol '_ZN4absl12lts_2024011612log_internal17MakeCheckOpStringImmEEPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEET_T0_PKc'
/usr/lib64/gcc/x86_64-suse-linux/13/../../../../x86_64-suse-linux/bin/ld: /home/danw/.conan2/p/b/absei344124e3560e9/p/lib/libabsl_log_internal_check_op.so.2401.0.0: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status

or similar. In the recipe for gRPC, the self.requires statement for abseil correctly adds the "transitive_headers=True" trait. It should also add the "transitive_libs=True", because downstream consumers need to link to the abseil shared library.

This is not true for static library usage, but unfortunately I don't see a way to detect whether abseil is a shared library at this point in the build. Using self.options['abseil'].shared doesn't seem to work, and of course `self.dependencies' doesn't exist at the time of the 'requirements()' method being called.

Package and Environment Details

Conan profile

[settings] arch=x86_64 build_type=RelWithDebInfo compiler=gcc compiler.cppstd=gnu20 compiler.libcxx=libstdc++11 compiler.version=13 os=Linux [buildenv] [conf] [options] grpc/:with_libsystemd=False /*:shared=True

Steps to reproduce

create package which uses grpc/1.65.0 as a dependency conan build . -oabseil/*:shared=True --build=missing

package build fails with missing DSO from command line related to absl

Logs

Click to expand log ``` [ 16%] Linking CXX executable asio_server_dev [ 18%] Linking CXX shared library libfoxtrot_server.so /usr/lib64/gcc/x86_64-suse-linux/13/../../../../x86_64-suse-linux/bin/ld: CMakeFiles/asio_server_dev.dir/asio_server_dev.cpp.o: undefined reference to symbol '_ZN4absl12lts_2024011612log_internal17MakeCheckOpStringImmEEPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEET_T0_PKc' /usr/lib64/gcc/x86_64-suse-linux/13/../../../../x86_64-suse-linux/bin/ld: /home/danw/.conan2/p/b/absei344124e3560e9/p/lib/libabsl_log_internal_check_op.so.2401.0.0: error adding symbols: DSO missing from command line collect2: error: ld returned 1 exit status gmake[2]: *** [devprogs/CMakeFiles/asio_server_dev.dir/build.make:123: devprogs/asio_server_dev] Error 1 gmake[1]: *** [CMakeFiles/Makefile2:350: devprogs/CMakeFiles/asio_server_dev.dir/all] Error 2 gmake[1]: *** Waiting for unfinished jobs.... [ 27%] Built target foxtrot_server gmake: *** [Makefile:136: all] Error 2 ERROR: conanfile.py (foxtrot_server/0.5.1-b2+dev-5-g90d8ee8-dirty): Error in build() method, line 110 cmake.build() ConanException: Error 2 while executing ```
jcar87 commented 1 month ago

hi @weatherhead99 - thank you for reporting this.

Would you be able to provide a minimal example of a consumer project that results in that linker error?

transitive_libs=True is hardly ever needed, as Conan handles that automatically depending on the package_type of the affected recipes - both abseil and grpc are of type library so Conan should handle this dynamically.

On the other hand, the grpc recipe already expresses that some components depend on abseil libraries - its a bit hard to see, but: https://github.com/conan-io/conan-center-index/blob/5cc80c47dd9e139a036d972debae9246fc39083d/recipes/grpc/all/conanfile.py#L344-L345

should be already "linking" the abseil targets: https://github.com/conan-io/conan-center-index/blob/5cc80c47dd9e139a036d972debae9246fc39083d/recipes/grpc/all/target_info/grpc_1.65.0.yml#L34-L50 -

I would have expected this to work already - but need to double check.

It would be useful if we had a way to repro this. transitive_libs=True can have the undersired effect of always linking all transitive libraries - which on some platforms/configurations can result in overlinking (linked binaries will require more libraries than they actually need at runtime)

memsharded commented 1 week ago

I am trying to reproduce this in Ubuntu 22.04, gcc11

My first attempt has been trying to use the grpc test_package in conan-center-index with:

conan create . --version=1.65.0 --build=missing -o abseil*:shared=True -o grpc/*:with_libsystemd=False

But this works fine. We would need a minimal full reproducible case to investigate this, can someone please provide one?

memsharded commented 1 week ago

All shared still works fine:

conan create . --version=1.65.0 --build=missing -o *:shared=True -o grpc/*:with_libsystemd=False
jcar87 commented 1 week ago

Thanks @weatherhead99 - we have fixed this now in the recipe, thanks for reporting this!