Skip to content

Commit

Permalink
Fix gRPC linking on ELF ABI.
Browse files Browse the repository at this point in the history
Signed-off-by: WenTao Ou <admin@owent.net>
  • Loading branch information
owent committed Apr 16, 2023
1 parent 33a8102 commit 8c6f07c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
9 changes: 8 additions & 1 deletion cmake/opentelemetry-proto.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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)
Expand Down
5 changes: 3 additions & 2 deletions exporters/otlp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 8c6f07c

Please sign in to comment.