diff --git a/cmake/opentelemetry-proto.cmake b/cmake/opentelemetry-proto.cmake index d6e9e1831c..07863b8f9b 100644 --- a/cmake/opentelemetry-proto.cmake +++ b/cmake/opentelemetry-proto.cmake @@ -232,6 +232,10 @@ include_directories("${GENERATED_PROTOBUF_PATH}") unset(OTELCPP_PROTO_TARGET_OPTIONS) if(CMAKE_SYSTEM_NAME MATCHES "Windows|MinGW|WindowsStore") list(APPEND OTELCPP_PROTO_TARGET_OPTIONS STATIC) +elseif(NOT DEFINED BUILD_SHARED_LIBS OR BUILD_SHARED_LIBS) + list(APPEND OTELCPP_PROTO_TARGET_OPTIONS SHARED) +else() + list(APPEND OTELCPP_PROTO_TARGET_OPTIONS STATIC) endif() list( @@ -288,7 +292,10 @@ if(WITH_OTLP_GRPC) target_link_libraries(opentelemetry_proto INTERFACE absl::synchronization) endif() endif() - target_link_libraries(opentelemetry_proto PUBLIC gRPC::grpc++) + + # gRPC can not be linked into more than one dynamic or executable targets. So + # we need to link it privately. + target_link_libraries(opentelemetry_proto PRIVATE gRPC::grpc++) endif() if(BUILD_SHARED_LIBS) diff --git a/exporters/otlp/CMakeLists.txt b/exporters/otlp/CMakeLists.txt index eed80783ac..b85b2532e9 100644 --- a/exporters/otlp/CMakeLists.txt +++ b/exporters/otlp/CMakeLists.txt @@ -35,8 +35,9 @@ if(WITH_OTLP_GRPC) opentelemetry_exporter_otlp_grpc_client PUBLIC opentelemetry_sdk opentelemetry_ext opentelemetry_proto) - target_link_libraries(opentelemetry_exporter_otlp_grpc_client - PRIVATE gRPC::grpc++) + # We have linked gRPC::grpc++ into opentelemetry_proto, so we must not link it + # again here.Otherwise the symbols of global variables in some version of gRPC + # will conflict on ELF ABI. get_target_property(GRPC_INCLUDE_DIRECTORY gRPC::grpc++ INTERFACE_INCLUDE_DIRECTORIES) if(GRPC_INCLUDE_DIRECTORY)