fix(testing_util): link opentelemetry-cpp SDK as PUBLIC#16101
fix(testing_util): link opentelemetry-cpp SDK as PUBLIC#16101GaetanLepage wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Code Review
This pull request updates the google_cloud_cpp_testing library in google/cloud/testing_util/CMakeLists.txt by moving the opentelemetry-cpp dependencies from PRIVATE to PUBLIC visibility. The reviewer suggested formatting the target_link_libraries list to have one dependency per line to improve readability and simplify future version control diffs.
| GTest::gmock opentelemetry-cpp::in_memory_span_exporter | ||
| opentelemetry-cpp::trace) |
There was a problem hiding this comment.
The `opentelemetry_matchers.h` public header of `google_cloud_cpp_testing`
includes and uses opentelemetry-cpp SDK symbols inline (e.g.
`sdk::trace::SpanData::GetAttributes()`). Tests that link
`google_cloud_cpp_testing` therefore reference these SDK symbols directly
from their own translation units.
However, the CMake build links `opentelemetry-cpp::in_memory_span_exporter`
and `opentelemetry-cpp::trace` as PRIVATE, so they are not propagated to
the test executables. When building with shared libraries this fails to
link, e.g.:
undefined reference to symbol
'...sdk::trace::SpanData::GetAttributes[abi:cxx11]() const'
libopentelemetry_trace.so: error adding symbols:
DSO missing from command line
The Bazel build already exposes these dependencies transitively (via
`google_cloud_cpp_testing_private`), so making the CMake link PUBLIC also
aligns the two build systems.
9fe0333 to
4912061
Compare
|
Thanks. I kept the dependencies packed rather than one-per-line because that's what this repository's |
Problem
google/cloud/testing_util/opentelemetry_matchers.his a public header of thegoogle_cloud_cpp_testingtarget, and it includes and uses opentelemetry-cpp SDK symbols inline (e.g.opentelemetry::sdk::trace::SpanData::GetAttributes()).Any test that links
google_cloud_cpp_testingand includes that header (e.g.google/cloud/internal/opentelemetry_test.cc) therefore references those SDK symbols directly from its own translation unit.The CMake build, however, links the SDK targets as
PRIVATE:So they are not propagated to the test executables. When building with shared libraries (
BUILD_SHARED_LIBS=ON), linking the test fails:because
libopentelemetry_trace.soonly arrives as an indirectDT_NEEDEDoflibgoogle_cloud_cpp_testing.so, which modern binutils refuses to resolve symbols from.Fix
Move
opentelemetry-cpp::in_memory_span_exporterandopentelemetry-cpp::traceto thePUBLIClink interface, since they are part of the public (header) interface ofgoogle_cloud_cpp_testing.Consistency with Bazel
The Bazel build already exposes these dependencies transitively:
:google_cloud_cpp_testingdepends on:google_cloud_cpp_testing_private, which lists@opentelemetry-cpp//exporters/memory:in_memory_span_exporterand@opentelemetry-cpp//sdk/src/traceindeps. This change aligns the CMake build with the existing Bazel behavior.Discovered while packaging google-cloud-cpp for nixpkgs (shared-library build with tests enabled).