opentelemetry-cpp icon indicating copy to clipboard operation
opentelemetry-cpp copied to clipboard

v1.22.0 no longer respects BUILD_SHARED_LIBS: ON

Open vkrevs opened this issue 4 months ago • 6 comments

Describe your environment openSUSE 15.6, gcc 7.5.0, cmake 4.0.3

We're trying to upgrade from v1.16.1 to v.1.22.0 and configuring opentelemetry-cpp v1.22.0 using the following command:

cmake <BUILD_ROOT>/opentelemetry-cpp-1.22.0 -DCMAKE_CXX_FLAGS="-std=c++14 -m64" \
-DCMAKE_TOOLCHAIN_FILE=build64.toolchain.cmake -DCMAKE_POSITION_INDEPENDENT_CODE=ON \
-DWITH_ABI_VERSION=2 -DWITH_ABI_VERSION_2=ON -DWITH_ABI_VERSION_1=OFF \
-DBUILD_SHARED_LIBS=ON -DBUILD_TESTING=OFF -DWITH_ABSEIL=ON \
-DWITH_DEPRECATED_SDK_FACTORY=OFF -DWITH_OTLP_GRPC=OFF -DWITH_OTLP_FILE=ON \
-DWITH_OTLP_HTTP=ON -DWITH_OTLP_HTTP_COMPRESSION=ON -DWITH_EXAMPLES_HTTP=OFF \
-DWITH_OTLP_HTTP_SSL_PREVIEW=ON -DWITH_OTLP_HTTP_SSL_TLS_PREVIEW=ON \
-DOTELCPP_PROTO_PATH=<BUILD_ROOT>/opentelemetry-proto-1.7.0 \
-DCMAKE_PREFIX_PATH=\
<BUILD_ROOT>/json-3.12.0-bin;\
<BUILD_ROOT>/zlib-1.3.1-bin;\
<BUILD_ROOT>/googletest-1.14.0-bin;\
<BUILD_ROOT>/benchmark-1.8.3-bin;\
<BUILD_ROOT>/protobuf-26.1-bin;\
<BUILD_ROOT>/abseil-cpp-20240116.2-bin

All dependencies including protobuf and abseil are built as static libraries. Dependency versions:

OPENTELEMETRY_VERSION=1.22.0
   OTEL_PROTO_VERSION=1.7.0
NLOHMANN_JSON_VERSION=3.12.0
     PROTOBUF_VERSION=26.1
    ABSEILCPP_VERSION=20240116.2
        GTEST_VERSION=1.14.0
       GBENCH_VERSION=1.8.3
         ZLIB_VERSION=1.3.1

Steps to reproduce Configure opentelemetry-cpp v1.22.0 using the above command. Then perform the "cmake --build" and "cmake --install" steps.

What is the expected behavior? What did you expect to see? The lib directory of the install location contains only shared libraries - just like it did in v1.16.1 - because of the -DBUILD_SHARED_LIBS=ON option.

What is the actual behavior? What did you see instead? The lib directory of the install location contains a mixture of shared and static libraries, despite the -DBUILD_SHARED_LIBS=ON option.

$ ls
libopentelemetry_common.so                     libopentelemetry_exporter_ostream_metrics.so  libopentelemetry_exporter_otlp_file_log.a         libopentelemetry_exporter_otlp_http_log.a       libopentelemetry_metrics.so         libopentelemetry_trace.so
libopentelemetry_exporter_in_memory_metric.so  libopentelemetry_exporter_ostream_span.so     libopentelemetry_exporter_otlp_file_metric.a      libopentelemetry_exporter_otlp_http64_metric.a  libopentelemetry_otlp_recordable.a  libopentelemetry_version.so
libopentelemetry_exporter_in_memory.so         libopentelemetry_exporter_otlp_file.a           libopentelemetry_exporter_otlp_http.a           libopentelemetry_http_client_curl.so            libopentelemetry_proto.a            pkgconfig
libopentelemetry_exporter_ostream_logs.so      libopentelemetry_exporter_otlp_file_client.a    libopentelemetry_exporter_otlp_http_client.a  libopentelemetry_logs.so                        libopentelemetry_resources.so

Additional context Add any other context about the problem here. I'm aware of https://github.com/open-telemetry/opentelemetry-cpp/issues/3405 and https://github.com/open-telemetry/opentelemetry-cpp/pull/3435. However, we're not using grpc at all, only protobuf and only indirectly - because opentelemetry-cpp requires it - and should not be affected by the problems with the latest protobuf versions - unless I misunderstand #3405 and #3435.

Tip: React with 👍 to help prioritize this issue. Please use comments to provide useful context, avoiding +1 or me too, to help us triage it. Learn more here.

vkrevs avatar Sep 01 '25 13:09 vkrevs

BUILD_SHARED_LIBS controls only the otel-cpp components, not third-party libraries. Use your package manager to install Abseil, Protobuf, Prometheus, and cURL. The build system may attempt to fetch missing dependencies for quick tests, but this is not required for otel-cpp.

owent avatar Sep 02 '25 13:09 owent

For various reasons, we have to build 3rd party libraries that opentelemetry-cpp depends upon ourselves without using package managers so your suggestion does not help us.

This bug report is not about 3rd party libraries that opentelemetry-cpp depends upon.

It is about BUILD_SHARED_LIBS:ON no longer working as before and breaking builds of openetelemetry-cpp consumers who reasonably expect BUILD_SHARED_LIBS:ON to produce only shared libraries, not a mixture of shared and static libraries.

vkrevs avatar Sep 02 '25 15:09 vkrevs

Sorry, I misunderstood the issue earlier. If the detected Protobuf is a static library, we build dependent components as static to maintain symbol compatibility. To build all OTLP and proto targets as shared libraries, compile Protobuf as a shared library.

owent avatar Sep 04 '25 02:09 owent

Yes, we could do that. Or we could switch to BUILD_SHARED_LIBS:OFF.

My point is that this change of behaviour - to successfully configure the opentelemetry-cpp build with BUILD_SHARED_LIBS:ON (or OFF for that matter) and after building end up with a mixture of static and shared opentelemetry-cpp libraries - is confusing and really unexpected.

It is also not mentioned in the changelog at all - I hope you agree that "[BUILD] Fixes grpc linking for OTLP exporter's tests" does not describe the full impact of the change, especially for those who do not build the OTLP GRPC exporter. There is no mention of this in https://github.com/open-telemetry/opentelemetry-cpp/blob/main/INSTALL.md either.

vkrevs avatar Sep 04 '25 12:09 vkrevs

Yes, we could do that. Or we could switch to BUILD_SHARED_LIBS:OFF.

My point is that this change of behaviour - to successfully configure the opentelemetry-cpp build with BUILD_SHARED_LIBS:ON (or OFF for that matter) and after building end up with a mixture of static and shared opentelemetry-cpp libraries - is confusing and really unexpected.

It is also not mentioned in the changelog at all - I hope you agree that "[BUILD] Fixes grpc linking for OTLP exporter's tests" does not describe the full impact of the change, especially for those who do not build the OTLP GRPC exporter. There is no mention of this in https://github.com/open-telemetry/opentelemetry-cpp/blob/main/INSTALL.md either.

Good point, we can also add a warning message for this case.

owent avatar Sep 05 '25 05:09 owent

This issue was marked as stale due to lack of activity.

github-actions[bot] avatar Nov 08 '25 02:11 github-actions[bot]