open-telemetry / opentelemetry-cpp

The OpenTelemetry C++ Client
https://opentelemetry.io/
Apache License 2.0
811 stars 391 forks source link

Example app example_otlp_http does not link because of missing references to functions in abseil, zlib etc. #2681

Open philrq opened 1 month ago

philrq commented 1 month ago

*Describe your environment

linux, gcc 7.3.1, protobuf 26.1, latest opentelemetry-cpp

Steps to reproduce

mkdir otel-cpp-starter cd otel-cpp-starter git clone https://github.com/open-telemetry/opentelemetry-cpp.git git submodule update --init cd opentelemetry-cpp mkdir build cd build cmake -DBUILD_TESTING=OFF -DWITH_OTLP_HTTP=ON -DCMAKE_CXX_STANDARD=17 -DBUILD_SHARED_LIBS=OFF -DWITH_ABSEIL=ON -Dabsl_ROOT=/home/abseil/Install -DCURL_LIBRARY=/home/libcurl/lib/libcurl.a -DCURL_INCLUDE_DIR=/home/libcurl/include -DCMAKE_PREFIX_PATH=/home/abseil/Install -DProtobuf_LIBRARIES=/tmp/protobuf/lib64/libprotobuf.a -DProtobuf_INCLUDE_DIR=/tmp/protobuf/include/ -DProtobuf_PROTOC_EXECUTABLE=/tmp/protobuf/bin/protoc ..

(works; no errors)

cmake --build . [ 6%] Built target opentelemetry_proto [ 10%] Built target opentelemetry_common [ 12%] Built target opentelemetry_resources [ 24%] Built target opentelemetry_trace [ 41%] Built target opentelemetry_metrics [ 54%] Built target opentelemetry_logs [ 56%] Built target opentelemetry_version [ 58%] Built target opentelemetry_http_client_curl [ 63%] Built target opentelemetry_otlp_recordable [ 65%] Built target opentelemetry_exporter_otlp_http_client [ 68%] Built target opentelemetry_exporter_otlp_http [ 70%] Built target opentelemetry_exporter_otlp_http_log [ 73%] Built target opentelemetry_exporter_otlp_http_metric [ 75%] Built target opentelemetry_exporter_ostream_span [ 77%] Built target opentelemetry_exporter_ostream_metrics [ 79%] Built target opentelemetry_exporter_ostream_logs [ 80%] Built target opentelemetry_exporter_in_memory [ 81%] Built target common_foo_library [ 82%] Built target common_logs_foo_library [ 84%] Built target common_metrics_foo_library [ 85%] Linking CXX executable example_otlp_http ../../exporters/otlp/libopentelemetry_exporter_otlp_http.a(otlp_http_exporter.cc.o): In function absl::log_internal::LogMessage::operator<<(unsigned long)': otlp_http_exporter.cc:(.text._ZN4absl12log_internal10LogMessagelsEm[_ZN4absl12log_internal10LogMessagelsEm]+0x1f): undefined reference toabsl::log_internal::LogMessage& absl::log_internal::LogMessage::operator<< <unsigned long, 0>(unsigned long const&)' ../../exporters/otlp/libopentelemetry_exporter_otlp_http.a(otlp_http_exporter.cc.o): In function google::protobuf::internal::ArenaAlignAs(unsigned long)': otlp_http_exporter.cc:(.text._ZN6google8protobuf8internal12ArenaAlignAsEm[_ZN6google8protobuf8internal12ArenaAlignAsEm]+0x74): undefined reference toabsl::log_internal::LogMessageFatal::LogMessageFatal(char const, int, std::basic_string_view<char, std::char_tr aits >)' otlp_http_exporter.cc:(.text._ZN6google8protobuf8internal12ArenaAlignAsEm[_ZN6google8protobuf8internal12ArenaAlignAsEm]+0x9e): undefined reference to absl::log_internal::LogMessageFatal::~LogMessageFatal()' otlp_http_exporter.cc:(.text._ZN6google8protobuf8internal12ArenaAlignAsEm[_ZN6google8protobuf8internal12ArenaAlignAsEm]+0xef): undefined reference toabsl::log_internal::LogMessageFatal::LogMessageFatal(char const, int, std::basic_string_view<char, std::char_tr aits >)'

(and many other link errors for functions from abseil, zlib etc).

What is the expected behavior? I expected the opentelemetry-cpp libraries and the executable example_otlp_http to be built correctly.

What is the actual behavior? The libraries have been built, but there were many link errors for example_otlp_http.

Additional context I have my own app which I'm trying to build against opentelemetry-cpp in order to send traces to Xray. It now compiles successfully (because I have modfied my first cmake invocation as shown above, and am now building againt protobuf, abseil etc) but I have similar link errors for abseil, zlib etc. My app build doesn't use cmake, but I would like to know how to get example_otlp_http to link in case it gives me any useful insights.

marcalff commented 1 month ago

Thanks for the report.

If I understand correctly, this build:

Protobuf 26.1requires Abseil LTS 20240116.2, as seen in:

https://github.com/protocolbuffers/protobuf/tree/v26.1/third_party

Please clarify:

philrq commented 1 month ago

Thanks for picking this up. I guess "uses its own version of abseil" means as opposed to using abseil as a git submodule of protobuf. The reason is that when I tried it this way, I got compilation error relating to filesystem, which I didn't see with my own version of abseil. However (i) I would rather use the standard approach and (ii) I can see I used the wrong version of abseil, so I'm trying again now. Unfortunately, I am having trouble with this; is this something you have experience of please? $ cmake -S. -Bcmake-out -DCMAKE_INSTALL_PREFIX=/tmp/protobuf -DCMAKE_CXX_STANDARD=17 -DBUILD_DEPS=ON -Dprotobuf_BUILD_TESTS=OFF -Dprotobuf_ABSL_PROVIDER=package -DCMAKE_PREFIX_PATH=/home/protobuf_2/src/protobuf/third_party/abseil-cpp

-- 26.1.0 CMake Error at cmake/abseil-cpp.cmake:36 (find_package): Could not find a package configuration file provided by "absl" with any of the following names:

abslConfig.cmake
absl-config.cmake

Add the installation prefix of "absl" to CMAKE_PREFIX_PATH or set "absl_DIR" to a directory containing one of the above files. If "absl" provides a separate development package or SDK, be sure it has been installed. Call Stack (most recent call first): CMakeLists.txt:296 (include)

-- Configuring incomplete, errors occurred!

philrq commented 1 month ago

In answer to you original question, the abseil build used for the opentelemetry build for which I initially reported the error was from master. Following my failed attempt to build protobuf with abseil as a submodule (above), I have gone back to cloning and building abseil manually, but this time choosing the correct branch, lts_2024_01_16. I now see a compilation error in the build of abseil (filesystem not found), which I have asked the abseil maintainers to help with.

marcalff commented 1 month ago

Thanks for the details.

Related to:

If I understand correctly, this looks like a bug in the main branch of abseil itself.

philrq commented 1 month ago

Possibly, especially where the undefined references to functions from abseil are concerned. Some of the linker errors from the opentelemetry build are for symbols defined in zlib, so the cause there could well be different.

philrq commented 1 month ago

Thanks for the details.

Related to:

If I understand correctly, this looks like a bug in the main branch of abseil itself.

Note that the abseil compilation error I have seen is only in lts_2024_01_16. Master compiles for me.

marcalff commented 1 week ago

Issue is caused upstream, and already fixed in main.

Keeping this issue open until there is a new abseil-cpp release with the fix.