Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[BUILD] Propagate INTERFACE_COMPILE_DEFINITIONS from API through common_foo_library #3440

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

Merged
merged 6 commits into from
May 28, 2025

Conversation

ThomsonTan
Copy link
Contributor

Fixes #3439

Changes

Please provide a brief description of the changes here.

For significant contributions please make sure you have completed the following items:

  • CHANGELOG.md updated for non-trivial changes
  • Unit tests have been added
  • Changes in public API reviewed

@ThomsonTan ThomsonTan requested a review from a team as a code owner May 23, 2025 03:10
Copy link

netlify bot commented May 23, 2025

Deploy Preview for opentelemetry-cpp-api-docs canceled.

Name Link
🔨 Latest commit 59d1fea
🔍 Latest deploy log https://app.netlify.com/projects/opentelemetry-cpp-api-docs/deploys/683774bfb805c80008ac4c58

Copy link

codecov bot commented May 23, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 89.88%. Comparing base (d99593f) to head (59d1fea).
Report is 1 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main    #3440   +/-   ##
=======================================
  Coverage   89.88%   89.88%           
=======================================
  Files         212      212           
  Lines        6941     6941           
=======================================
  Hits         6238     6238           
  Misses        703      703           
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@@ -12,4 +12,4 @@ endif()

target_include_directories(common_foo_library
PUBLIC "$<BUILD_INTERFACE:${EXAMPLES_COMMON_DIR}>")
target_link_libraries(common_foo_library PRIVATE opentelemetry-cpp::api)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The example common foo library headers don't expose otel-cpp headers and that seems to be an important aspect of the example (user instrumentation of a library shouldn't leak otel-cpp if it doesn't need to).

If the executable linking to the dll target opentelemetry-cpp::opentelemetry_cpp isn't getting the definitions it needs from the api target, then it points to a missing link by the dll target.

Can you try adding target_link_libraries(opentelemetry_cpp INTERFACE opentelemetry_api) to the dll's cmake file?

add_library(opentelemetry_cpp SHARED dllmain.cc ${OPENTELEMETRY_EXPORT_DEF})

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No strong opinion whether the original fix from @ThomsonTan or the suggestion from @dbarker is the best solution.

Please resolve the code review, so a fix we all agree with can go in the repo.

This is blocking for the next release 1.21.0, as we want to make sure that examples work properly with a consistent build, it affects people trying / evaluating opentelemetry-cpp.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@marcalff Okay to merge now to fix the new examples build and unblock the release.

Users who link to the dll target in their projects will need to explicitly link the API target to get its declarations until we add the API link to the dll target. This can be done in the next release since the issue is not new

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the suggestion from @dbarker with target_link_libraries(opentelemetry_cpp INTERFACE opentelemetry_api) could fix the issue, but I suspect the same issue could happen to non-DLL case, probably somehow there is some fallback for the linking in the same executable.

I also suggest we merge the current PR and tune the fix later (after the release), because the current PR restores the previous behavior.

File a new issue to track the follow-up #3447.

@dbarker
Copy link
Contributor

dbarker commented May 23, 2025

Can you add a test in ci to cover the error you're seeing?

@marcalff marcalff added issue:blocking This issue is preventing other fixes pr:please-review This PR is ready for review labels May 28, 2025
@ThomsonTan
Copy link
Contributor Author

Can you add a test in ci to cover the error you're seeing?

I am running a repro for the issue in below draft, and post it back once it is ready.

#3441

@ThomsonTan
Copy link
Contributor Author

Can you add a test in ci to cover the error you're seeing?

I am running a repro for the issue in below draft, and post it back once it is ready.

#3441

And the unresolved symbol issue for linking does repro in the CI build. I'll clean PR #3441 to make it ready for review, but I think it doesn't block the coming release.

https://github.com/open-telemetry/opentelemetry-cpp/actions/runs/15309964132/job/43072033016?pr=3441

D:\a\opentelemetry-cpp\opentelemetry-cpp\build\examples\simple\Debug\example_simple.exe : fatal error LNK1120: 1 unresolved externals [D:\a\opentelemetry-cpp\opentelemetry-cpp\build\examples\simple\example_simple.vcxproj]
main.obj : error LNK2019: unresolved external symbol "public: static void __cdecl opentelemetry::v1::sdk::logs::Provider::SetLoggerProvider(class opentelemetry::v1::nostd::shared_ptr const &)" (?SetLoggerProvider@Provider@logs@sdk@v1@opentelemetry@@SAXAEBV?$shared_ptr@VLoggerProvider@logs@v1@opentelemetry@@@nostd@45@@z) referenced in function "void __cdecl anonymous namespace'::InitLogger(void)" (?InitLogger@?A0x8fabb68e@@YAXXZ) [D:\a\opentelemetry-cpp\opentelemetry-cpp\build\examples\logs_simple\example_logs_simple.vcxproj] main.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: static void __cdecl opentelemetry::v1::sdk::trace::Provider::SetTracerProvider(class opentelemetry::v1::nostd::shared_ptr<class opentelemetry::v1::trace::TracerProvider> const &)" (__imp_?SetTracerProvider@Provider@trace@sdk@v1@opentelemetry@@SAXAEBV?$shared_ptr@VTracerProvider@trace@v1@opentelemetry@@@nostd@45@@Z) referenced in function "void __cdecl anonymous namespace'::InitTracer(void)" (?InitTracer@?A0x8fabb68e@@yaxxz) [D:\a\opentelemetry-cpp\opentelemetry-cpp\build\examples\logs_simple\example_logs_simple.vcxproj]

@marcalff
Copy link
Member

@ThomsonTan @dbarker So, for clarity: ok to merge this PR, 3440, as is then ?

@ThomsonTan
Copy link
Contributor Author

@ThomsonTan @dbarker So, for clarity: ok to merge this PR, 3440, as is then ?

Yes, it is good to merge the current PR on my side and include it in the pending release. Will see if there is any further feedback from @dbarker.

@marcalff marcalff merged commit 793c7bd into open-telemetry:main May 28, 2025
67 checks passed
@marcalff marcalff removed issue:blocking This issue is preventing other fixes pr:please-review This PR is ready for review labels May 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Examples build is broken in Windows DLL build
4 participants