open-telemetry / open-telemetry/opentelemetry-cpp

opentelemetry::v2::context::propagation::GlobalTextMapPropagator should not be marked with OPENTELEMETRY_EXPORT

Open
#3,674 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Describe your environment
Same as in https://github.com/open-telemetry/opentelemetry-cpp/issues/3673

Steps to reproduce
Same as in https://github.com/open-telemetry/opentelemetry-cpp/issues/3673, except that ext/src/dll/input.src is patched with the missing symbols listed in https://github.com/open-telemetry/opentelemetry-cpp/issues/3673 before building the opentelemetry-cpp DLL.

Then attempt to link the resulting import library on Windows into another shared library uses traces, exporters, resources, samplers, etc

What is the expected behavior?
What did you expect to see?
Successful link without unresolved symbols, just like on Linux.

What is the actual behavior?
What did you see instead?

14>   Creating library <x86 or x64>\Release\project1\\project1.lib and object x64\Release\project1\\project1.exp
14>file1.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: static class opentelemetry::v2::nostd::shared_ptr<class opentelemetry::v2::context::propagation::TextMapPropagator> __cdecl opentelemetry::v2::context::propagation::GlobalTextMapPropagator::GetGlobalPropagator(void)" (__imp_?GetGlobalPropagator@GlobalTextMapPropagator@propagation@context@v2@opentelemetry@@SA?AV?$shared_ptr@VTextMapPropagator@propagation@context@v2@opentelemetry@@@nostd@45@XZ) referenced in function "<function1>)
14>file2.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: static void __cdecl opentelemetry::v2::context::propagation::GlobalTextMapPropagator::SetGlobalPropagator(class opentelemetry::v2::nostd::shared_ptr<class opentelemetry::v2::context::propagation::TextMapPropagator> const &)" (__imp_?SetGlobalPropagator@GlobalTextMapPropagator@propagation@context@v2@opentelemetry@@SAXAEBV?$shared_ptr@VTextMapPropagator@propagation@context@v2@opentelemetry@@@nostd@45@@Z) referenced in function "<function2>)
14><path to final dll>\project1.dll : fatal error LNK1120: 2 unresolved externals
14>Done building project "project1.vcxproj" -- FAILED.

Additional context
This is because the GlobalPropagator class is annotated with the OPENTELEMETRY_EXPORT macro. It's a header-only class. Nothing inside opentelemetry-cpp source files actually uses the GlobalPropagator class. So the resulting DLL has no symbols corresponding to the GlobalPropagator class and/or methods.

Hence when we attempt to use the GlobalPropagator class in our code, OPENTELEMETRY_EXPORT is expanded into "__declspec(dllimport)" and hence the missing symbol.

If I remove OPENTELEMETRY_EXPORT from GlobalPropagator, then all is good and the link works. I suspect that if opentelemetry-cpp's sources actually used the GlobalPropagator class somewhere (or did not use static singletons in the header ...) then it would work with the OPENTELEMETRY_EXPORT macro.

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.

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.

Research direction

Locate the declaration of GlobalTextMapPropagator and its OPENTELEMETRY_EXPORT annotation, using the Windows reproduction and ext/src/dll/input.src context from the issue. Verify the export behavior by building the opentelemetry-cpp DLL and linking a shared library that calls GetGlobalPropagator and SetGlobalPropagator; done means the Windows link has no unresolved symbols.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
build-system
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.