open-telemetry / open-telemetry/opentelemetry-cpp

cmake does not find the includes

Open
#3,470 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

I'm incorporating the OpenTelemetry C++ library (v1.8.3) into my project using a CMake helper that creates "imported static" targets with their own include paths and .a files. However, when I link the opentelemetry-cpp::metrics target into a metrics submodule of my engine, the compiler can't find the OpenTelemetry SDK headers.

Makefile rule


### opentelemetry ###
${OPENTELEMETRY_LIB}:
	cd $(EXTERNAL_OPENTELEMETRY) && mkdir -p build && cd build && cmake .. -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTING=OFF -DWITH_EXAMPLES=OFF -DOPENTELEMETRY_INSTALL=ON -DWITH_ABSEIL=OFF -DWITH_STL=ON -DWITH_BENCHMARK=OFF && ${MAKE}
/ruta/al/proyecto/
├── external/
│   └── opentelemetry-cpp-1_8_3/
│       ├── opentelemetry-cpp-1.8.3/
│       │   ├── api/
│       │   │   └── include/opentelemetry/…
│       │   └── sdk/
│       │       └── include/opentelemetry/sdk/metrics/…
│       └── build/
│           └── sdk/src/metrics/libopentelemetry_metrics.a
├── engine/                                    # target de nivel superior
│   ├── CMakeLists.txt                         # Here I define the helper
│   └── metrics/                               # submodule “metrics”
│       └── CMakeLists.txt                     # Here I link against OpenTelemetry
├── Makefile

Helper

function(add_manual_imported alias header_dir static_lib)
  string(REPLACE "::" "_" internal "${alias}")
  if(static_lib)
    add_library(${internal} STATIC IMPORTED GLOBAL)
    set_target_properties(${internal} PROPERTIES
      IMPORTED_LOCATION           "${static_lib}"
      INTERFACE_INCLUDE_DIRECTORIES "${header_dir}"
    )
  else()
    add_library(${internal} INTERFACE IMPORTED GLOBAL)
    set_target_properties(${internal} PROPERTIES
      INTERFACE_INCLUDE_DIRECTORIES "${header_dir}"
    )
  endif()
  add_library(${alias} ALIAS ${internal})
endfunction()

add_manual_imported(
  opentelemetry-cpp::metrics
  "${PROJECT_SOURCE_DIR}/../external/opentelemetry-cpp-1_8_3/opentelemetry-cpp-1.8.3/sdk/include"
  "${PROJECT_SOURCE_DIR}/../external/opentelemetry-cpp-1_8_3/opentelemetry-cpp-1.8.3/build/sdk/src/metrics/libopentelemetry_metrics.a"
)

so I link in the submodule engine/metrics/CMakeLists.txt

target_link_libraries(metrics
  PUBLIC
    metrics::imetrics
    base
  PRIVATE
    opentelemetry-cpp::metrics    # Here I use the imported target
)

Observed behavior

When compiling the metrics submodule, any line like

#include <opentelemetry/sdk/metrics/push_metric_exporter.h>

produces a “file not found” error

Additional Information

CMake Version: 3.24

Platform: Ubuntu 22.04

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 engine/CMakeLists.txt and engine/metrics/CMakeLists.txt, focusing on add_manual_imported and the opentelemetry-cpp::metrics link. Reproduce the missing-header error on Ubuntu 22.04 with CMake 3.24 and inspect the imported target's include paths. Done means the metrics submodule can compile the stated OpenTelemetry SDK include.

Written by the indexing model from the issue text.

Assessment

Tech stack
cmake, cpp
Domain
build-system
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.