open-telemetry / open-telemetry/opentelemetry-cpp

otlp_grpc_metrics_exporter linker error multiple definition of absl Status kMovedFromString

Open
#3,301 2 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug triage/needs-information
Dominant language
C++
Stars
1.4k
Forks
632
Avg merge
1d 13h
Merged PRs (30d)
75

Description

Describe your environment
WSL -> Ubuntu 20.04.6 LTS
gcc version 9.4.0

Steps to reproduce
Vcpkg manifest:

{
  "dependencies": [
    {
      "name": "opentelemetry-cpp",
      "features": [
        "otlp-grpc"
      ],
      "version>=" : "1.19.0"
    }
  ],
  "builtin-baseline": "1f3f10d4911f46339411e12b1d0947c22bad5937"
}

CMakeLists.txt

find_package(opentelemetry-cpp CONFIG REQUIRED COMPONENTS)

add_executable(otlpgrpcmain
    ./src/otlpgrpcmain.cpp
)

target_link_libraries(otlpgrpcmain
    opentelemetry-cpp::otlp_grpc_metrics_exporter
)

Simple sample app:

#include "opentelemetry/exporters/otlp/otlp_grpc_metric_exporter_factory.h"
#include "opentelemetry/metrics/provider.h"
#include "opentelemetry/sdk/metrics/export/periodic_exporting_metric_reader.h"
#include "opentelemetry/sdk/metrics/meter_provider.h"

namespace otlp_exporter   = opentelemetry::exporter::otlp;
namespace metrics_api     = opentelemetry::metrics;
namespace metrics_sdk     = opentelemetry::sdk::metrics;

int main(int argc, char** argv)
{
    std::shared_ptr<metrics_api::MeterProvider> apiProvider;

    otlp_exporter::OtlpGrpcMetricExporterOptions options;
    options.endpoint = "collector-endpoint:4317";
    std::unique_ptr<metrics_sdk::PushMetricExporter> exporter = otlp_exporter::OtlpGrpcMetricExporterFactory::Create(options);

    // Initialize and set the MeterProvider
    metrics_sdk::PeriodicExportingMetricReaderOptions reader_options;
    std::unique_ptr<metrics_sdk::MetricReader>        reader = std::make_unique<metrics_sdk::PeriodicExportingMetricReader>(std::move(exporter), reader_options);

    apiProvider      = std::make_shared<metrics_sdk::MeterProvider>();
    auto sdkProvider = std::static_pointer_cast<metrics_sdk::MeterProvider>(apiProvider);
    sdkProvider->AddMetricReader(std::move(reader));

    return 0;
}

What is the expected behavior?
Expect to compile and link succesfully

What is the actual behavior?
Linker error:
[100%] Linking CXX executable otlpgrpcmain
/usr/bin/ld: vcpkg_installed/x64-linux/debug/lib/libabsl_status.a(status.cc.o):(.rodata+0x320): multiple definition of `absl::lts_20240722::Status::kMovedFromString'; vcpkg_installed/x64-linux/debug/lib/libgrpc.a(client_channel_service_config.cc.o):(.rodata._ZN4absl12lts_202407226Status16kMovedFromStringE[_ZN4absl12lts_202407226Status16kMovedFromStringE]+0x0): first defined here
collect2: error: ld returned 1 exit status

Additional context
N/A

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the vcpkg manifest, CMakeLists.txt, and the sample application, then reproduce the link using the otlp_grpc_metrics_exporter target. Inspect the linked libabsl_status.a and libgrpc.a versions around the reported kMovedFromString definitions. Done means the sample links successfully without the multiple-definition error.

Written by the indexing model from the issue text.

Assessment

Tech stack
cmake, cpp, grpc
Domain
build-system, observability
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.