open-telemetry / open-telemetry/opentelemetry-cpp

Undefined symbol when building OLTP with shared libraries on Mac OS

Open
#2,090 9 comments 0 reactions 1 assignee View on GitHub

Nobody has claimed this yet.

bug do-not-stale triage/accepted
Dominant language
C++
Stars
1.4k
Forks
632
Avg merge
1d 13h
Merged PRs (30d)
75

Description

Describe your environment

When building from the master branch on MacOS, if BUILD_SHARED_LIBS=ON and either WITH_OLTP_HTTP=ON or WITH_OLTP_GRPC are on then we get build errors:

[1/16] Linking CXX shared library ext/src/http/client/curl/libopentelemetry_http_client_curl.dylib
FAILED: ext/src/http/client/curl/libopentelemetry_http_client_curl.dylib 
: && /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ -O3 -DNDEBUG -arch arm64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.3.sdk -dynamiclib -Wl,-headerpad_max_install_names  -o ext/src/http/client/curl/libopentelemetry_http_client_curl.dylib -install_name @rpath/libopentelemetry_http_client_curl.dylib ext/src/http/client/curl/CMakeFiles/opentelemetry_http_client_curl.dir/http_client_factory_curl.cc.o ext/src/http/client/curl/CMakeFiles/opentelemetry_http_client_curl.dir/http_client_curl.cc.o ext/src/http/client/curl/CMakeFiles/opentelemetry_http_client_curl.dir/http_operation_curl.cc.o  /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.3.sdk/usr/lib/libcurl.tbd && :
Undefined symbols for architecture arm64:
  "opentelemetry::v1::sdk::common::internal_log::GlobalLogHandler::GetHandlerAndLevel()", referenced from:
      opentelemetry::v1::ext::http::client::curl::HttpOperation::SetCurlPtrOption(CURLoption, void*) in http_operation_curl.cc.o
      opentelemetry::v1::ext::http::client::curl::HttpOperation::SetCurlLongOption(CURLoption, long) in http_operation_curl.cc.o
      opentelemetry::v1::ext::http::client::curl::HttpOperation::Setup() in http_operation_curl.cc.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
[2/16] Linking CXX shared library exporters/ostream/libopentelemetry_exporter_ostream_metrics.dylib
FAILED: exporters/ostream/libopentelemetry_exporter_ostream_metrics.dylib 
: && /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ -O3 -DNDEBUG -arch arm64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.3.sdk -dynamiclib -Wl,-headerpad_max_install_names  -o exporters/ostream/libopentelemetry_exporter_ostream_metrics.dylib -install_name @rpath/libopentelemetry_exporter_ostream_metrics.dylib exporters/ostream/CMakeFiles/opentelemetry_exporter_ostream_metrics.dir/src/metric_exporter.cc.o  -Wl,-rpath,/Users/willjones/Documents/opentelemetry-cpp/build/sdk/src/metrics -Wl,-rpath,/Users/willjones/Documents/opentelemetry-cpp/build/sdk/src/common  sdk/src/metrics/libopentelemetry_metrics.dylib  sdk/src/common/libopentelemetry_common.dylib && :
Undefined symbols for architecture arm64:
  "opentelemetry::v1::sdk::resource::Resource::GetAttributes() const", referenced from:
      opentelemetry::v1::exporter::metrics::OStreamMetricExporter::printResources(opentelemetry::v1::sdk::resource::Resource const&) in metric_exporter.cc.o
ld: symbol(s) not found for architecture arm64

Steps to reproduce

git clone git@github.com:open-telemetry/opentelemetry-cpp.git
cd opentelemetry-cpp

mkdir build
pushd build

mamba create -y -n otel-build \
       --channel=conda-forge
       clang_osx-arm64=14 \
       clang-tools=14 \
       libprotobuf=3.19 \
       python=3.9

cmake ${CMAKE_ARGS} ..  \
          -GNinja \
          -DCMAKE_BUILD_TYPE=Release \
          -DBUILD_SHARED_LIBS=ON \
          -DCMAKE_CXX_FLAGS="$CXXFLAGS" \
          -DCMAKE_CXX_STANDARD=17 \
          -DCMAKE_PREFIX_PATH=$CONDA_PREFIX \
          -DCMAKE_INSTALL_PREFIX=$CONDA_PREFIX \
          -DBUILD_TESTING=OFF \
          -DOPENTELEMETRY_INSTALL=ON \
          -DWITH_API_ONLY=OFF \
          -DWITH_BENCHMARK=OFF \
          -DWITH_EXAMPLES=OFF \
          -DWITH_LOGS_PREVIEW=ON \
          -DWITH_OTLP=ON \
          -DWITH_OTLP_HTTP=OFF \
          -DWITH_OTLP_GRPC=ON \
          -DWITH_PROMETHEUS=ON \
          -DWITH_ZIPKIN=ON

ninja install

What is the expected behavior?

I expected the build to create shared libraries without error.

What is the actual behavior?

Got the linking errors described above.

Additional context

I discovered this issue while trying to setup conda-forge to distribute shared libraries.

https://github.com/conda-forge/cpp-opentelemetry-sdk-feedstock/pull/41

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.