open-telemetry / open-telemetry/opentelemetry-cpp
cmake does not find the includes
Nobody has claimed this yet.
- 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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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