Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OTel opentelemetry-cpp::otlp_grpc_client target is not linked correctly #2443

Closed
alevenberg opened this issue Dec 8, 2023 · 2 comments
Closed
Labels
bug Something isn't working triage/not-reproducible Indicates an issue can not be reproduced as described.

Comments

@alevenberg
Copy link

alevenberg commented Dec 8, 2023

I tried to compile an application using CMake and VcPkg

Steps to reproduce

Here's a simple version

publisher_jaeger.cc

namespace trace_sdk = opentelemetry::sdk::trace;
namespace otlp = opentelemetry::exporter::otlp;

namespace {

void ConfigureOtlpGrpcExporterTracer(ParseResult const& args) {
  otlp::OtlpGrpcExporterOptions opts;
  auto exporter = otlp::OtlpGrpcExporterFactory::Create(opts);
  trace_sdk::BatchSpanProcessorOptions span_options;
  span_options.max_queue_size = args.max_queue_size;
  auto processor = trace_sdk::BatchSpanProcessorFactory::Create(
      std::move(exporter), span_options);
  auto provider =
      trace_sdk::TracerProviderFactory::Create(std::move(processor));
  opentelemetry::trace::Provider::SetTracerProvider(std::move(provider));
}

}  // namespace

int main(int argc, char* argv[]) try {
  ConfigureOtlpGrpcExporterTracer(args);
  return 0;
} 

CMakeLists.txt

add_executable(publisher_jaeger publisher_jaeger.cc)
target_compile_features(publisher_jaeger PRIVATE cxx_std_14)
target_link_libraries(
    publisher_jaeger
    PRIVATE opentelemetry-cpp::otlp_grpc_client
            opentelemetry-cpp::otlp_grpc_exporter
            opentelemetry-cpp::otlp_recordable)

Steps to build

cmake -DWITH_OTLP_GRPC=ON -S . -B .build -DCMAKE_TOOLCHAIN_FILE=$HOME/vcpkg/scripts/buildsystems/vcpkg.cmake -G Ninja
cmake --build .build --target publisher_jaeger

At the build step, it found the target, but produced a linking error.

What is the expected behavior?
What did you expect to see?
No error and a successful linking

What is the actual behavior?
A linking error saying otlp:: symbols were not found

/usr/bin/ld: CMakeFiles/publisher_jaeger.dir/publisher_jaeger.cc.o: in function `(anonymous namespace)::ConfigureOtlpGrpcExporterTracer(ParseResult const&)':
publisher_jaeger.cc:(.text+0x65): undefined reference to `opentelemetry::v1::exporter::otlp::OtlpGrpcExporterFactory::Create(opentelemetry::v1::exporter::otlp::OtlpGrpcExporterOptions const&)'
/usr/bin/ld: CMakeFiles/publisher_jaeger.dir/publisher_jaeger.cc.o: in function `opentelemetry::v1::exporter::otlp::GetOtlpDefaultGrpcEndpoint[abi:cxx11]()':
publisher_jaeger.cc:(.text._ZN13opentelemetry2v18exporter4otlp26GetOtlpDefaultGrpcEndpointB5cxx11Ev[_ZN13opentelemetry2v18exporter4otlp26GetOtlpDefaultGrpcEndpointB5cxx11Ev]+0x14): undefined reference to `opentelemetry::v1::exporter::otlp::GetOtlpDefaultGrpcTracesEndpoint[abi:cxx11]()'
/usr/bin/ld: CMakeFiles/publisher_jaeger.dir/publisher_jaeger.cc.o: in function `opentelemetry::v1::exporter::otlp::GetOtlpDefaultIsSslEnable()':
publisher_jaeger.cc:(.text._ZN13opentelemetry2v18exporter4otlp25GetOtlpDefaultIsSslEnableEv[_ZN13opentelemetry2v18exporter4otlp25GetOtlpDefaultIsSslEnableEv]+0x5): undefined reference to `opentelemetry::v1::exporter::otlp::GetOtlpDefaultGrpcTracesIsInsecure()'
/usr/bin/ld: CMakeFiles/publisher_jaeger.dir/publisher_jaeger.cc.o: in function `opentelemetry::v1::exporter::otlp::GetOtlpDefaultSslCertificatePath[abi:cxx11]()':
publisher_jaeger.cc:(.text._ZN13opentelemetry2v18exporter4otlp32GetOtlpDefaultSslCertificatePathB5cxx11Ev[_ZN13opentelemetry2v18exporter4otlp32GetOtlpDefaultSslCertificatePathB5cxx11Ev]+0x14): undefined reference to `opentelemetry::v1::exporter::otlp::GetOtlpDefaultTracesSslCertificatePath[abi:cxx11]()'
/usr/bin/ld: CMakeFiles/publisher_jaeger.dir/publisher_jaeger.cc.o: in function `opentelemetry::v1::exporter::otlp::GetOtlpDefaultSslCertificateString[abi:cxx11]()':
publisher_jaeger.cc:(.text._ZN13opentelemetry2v18exporter4otlp34GetOtlpDefaultSslCertificateStringB5cxx11Ev[_ZN13opentelemetry2v18exporter4otlp34GetOtlpDefaultSslCertificateStringB5cxx11Ev]+0x14): undefined reference to `opentelemetry::v1::exporter::otlp::GetOtlpDefaultTracesSslCertificateString[abi:cxx11]()'
/usr/bin/ld: CMakeFiles/publisher_jaeger.dir/publisher_jaeger.cc.o: in function `opentelemetry::v1::exporter::otlp::GetOtlpDefaultTimeout()':
publisher_jaeger.cc:(.text._ZN13opentelemetry2v18exporter4otlp21GetOtlpDefaultTimeoutEv[_ZN13opentelemetry2v18exporter4otlp21GetOtlpDefaultTimeoutEv]+0x5): undefined reference to `opentelemetry::v1::exporter::otlp::GetOtlpDefaultTracesTimeout()'
/usr/bin/ld: CMakeFiles/publisher_jaeger.dir/publisher_jaeger.cc.o: in function `opentelemetry::v1::exporter::otlp::GetOtlpDefaultHeaders[abi:cxx11]()':
publisher_jaeger.cc:(.text._ZN13opentelemetry2v18exporter4otlp21GetOtlpDefaultHeadersB5cxx11Ev[_ZN13opentelemetry2v18exporter4otlp21GetOtlpDefaultHeadersB5cxx11Ev]+0x14): undefined reference to `opentelemetry::v1::exporter::otlp::GetOtlpDefaultTracesHeaders[abi:cxx11]()'

Additional context

A workaround is linking to two more libraries, then it compiles and the linking error goes away.

target_link_libraries(
    publisher_jaeger
    PRIVATE publisher_helper parse_args opentelemetry-cpp::otlp_grpc_client
            opentelemetry-cpp::otlp_grpc_exporter
            opentelemetry-cpp::otlp_recordable)

I'm not sure if the solution is to link the additional targets for otlp_grpc_client, or if the common symbols should be refactored into a private library, so filing the issue for the maintainers to decide

This is where the links could be added

target_link_libraries(
opentelemetry_exporter_otlp_grpc_client
PUBLIC opentelemetry_sdk opentelemetry_common opentelemetry_ext
# gRPC::grpc++ must be linked before opentelemetry_proto_grpc.
opentelemetry_proto_grpc
PRIVATE gRPC::grpc++)
.

@alevenberg alevenberg added the bug Something isn't working label Dec 8, 2023
@github-actions github-actions bot added the needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. label Dec 8, 2023
@owent
Copy link
Member

owent commented Dec 11, 2023

You can use gRPC trace exporter by only link opentelemetry-cpp::otlp_grpc_exporter, opentelemetry-cpp::otlp_grpc_client and opentelemetry-cpp::otlp_recordable should be linked automaticlly because them are depended by opentelemetry-cpp::otlp_grpc_exporter.
But it's not a problem of the linking problem above, could you please add --verbose to cmake --build ... we we can find out which library files are actually linked?And then we can use nm to find out the symbols in libopentelemetry_otlp_recordable.a or libopentelemetry_otlp_recordable.so.
In my guess, there may be more than one otel-cpp in your build system and publisher_jaeger may just link a wrong one.

@alevenberg
Copy link
Author

Thanks for taking a look.

I tried it again and only linked opentelemetry-cpp::otlp_grpc_exporter and opentelemetry-cpp::otlp_grpc_client and it built correctly.

@marcalff marcalff added triage/not-reproducible Indicates an issue can not be reproduced as described. and removed needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. labels Dec 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working triage/not-reproducible Indicates an issue can not be reproduced as described.
Projects
None yet
Development

No branches or pull requests

3 participants