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

Can not compile when using clang with cmake and -DWITH_STL=ON #1851

Closed
owent opened this issue Dec 8, 2022 · 5 comments · Fixed by #1852
Closed

Can not compile when using clang with cmake and -DWITH_STL=ON #1851

owent opened this issue Dec 8, 2022 · 5 comments · Fixed by #1852
Assignees
Labels
bug Something isn't working

Comments

@owent
Copy link
Member

owent commented Dec 8, 2022

Describe your environment

OS: Ubuntu 22.04
Compiler: Clang 14 with -stdlib=libc++
Otel-cpp version: v1.8.1

Steps to reproduce
Describe exactly how to reproduce the error. Include a code sample if applicable.

What is the expected behavior?
Compiling success.

What is the actual behavior?

 [ 35%] Building CXX object sdk/src/trace/CMakeFiles/opentelemetry_trace.dir/samplers/always_on_factory.cc.o
In file included from /home/runner/work/cmake-toolset/cmake-toolset/test/third_party/packages/opentelemetry-cpp-v1.8.1/sdk/src/trace/simple_processor_factory.cc:5:
/home/runner/work/cmake-toolset/cmake-toolset/test/third_party/packages/opentelemetry-cpp-v1.8.1/sdk/include/opentelemetry/sdk/trace/simple_processor.h:76:38: warning: macro 'ATOMIC_FLAG_INIT' has been marked as deprecated [-Wdeprecated-pragma]
  std::atomic_flag shutdown_latch_ = ATOMIC_FLAG_INIT;
                                     ^
/usr/lib/llvm-14/bin/../include/c++/v1/atomic:2712:44: note: macro marked 'deprecated' here
#  pragma clang deprecated(ATOMIC_FLAG_INIT)

/home/runner/work/cmake-toolset/cmake-toolset/test/third_party/packages/opentelemetry-cpp-v1.8.1/sdk/src/metrics/meter_context.cc:48:10: error: no matching constructor for initialization of 'nostd::span<std::shared_ptr<Meter>>' (aka 'span<std::shared_ptr<opentelemetry::sdk::metrics::Meter>, 18446744073709551615UL>')
  return nostd::span<std::shared_ptr<Meter>>{meters_};
         ^                                  ~~~~~~~~~
/usr/lib/llvm-14/bin/../include/c++/v1/span:401:15: note: candidate constructor not viable: no known conversion from 'std::vector<std::shared_ptr<Meter>>' to 'const std::span<std::shared_ptr<opentelemetry::sdk::metrics::Meter>, 18446744073709551615>' for 1st argument
    constexpr span           (const span&) noexcept = default;
              ^
/usr/lib/llvm-14/bin/../include/c++/v1/span:425:15: note: candidate template ignored: could not match 'type_identity_t<std::span<std::shared_ptr<opentelemetry::sdk::metrics::Meter>, 18446744073709551615>::element_type>[_Sz]' (aka 'std::shared_ptr<opentelemetry::sdk::metrics::Meter>[_Sz]') against 'std::vector<std::shared_ptr<Meter>>'
    constexpr span(type_identity_t<element_type> (&__arr)[_Sz]) noexcept : __data{__arr}, __size{_Sz} {}
              ^
/usr/lib/llvm-14/bin/../include/c++/v1/span:430:15: note: candidate template ignored: could not match 'array' against 'vector'
    constexpr span(array<_OtherElementType, _Sz>& __arr) noexcept : __data{__arr.data()}, __size{_Sz} {}
              ^
/usr/lib/llvm-14/bin/../include/c++/v1/span:435:15: note: candidate template ignored: could not match 'array' against 'vector'
    constexpr span(const array<_OtherElementType, _Sz>& __arr) noexcept : __data{__arr.data()}, __size{_Sz} {}
              ^
/usr/lib/llvm-14/bin/../include/c++/v1/span:445:19: note: candidate template ignored: could not match 'span' against 'vector'
        constexpr span(const span<_OtherElementType, _OtherExtent>& __other,
                  ^
/usr/lib/llvm-14/bin/../include/c++/v1/span:399:41: note: candidate constructor not viable: requires 0 arguments, but 1 was provided
    _LIBCPP_INLINE_VISIBILITY constexpr span() noexcept : __data{nullptr}, __size{0} {}
                                        ^
/usr/lib/llvm-14/bin/../include/c++/v1/span:410:15: note: candidate constructor template not viable: requires 2 arguments, but 1 was provided
    constexpr span(_It __first, size_type __count)
              ^
/usr/lib/llvm-14/bin/../include/c++/v1/span:419:15: note: candidate constructor template not viable: requires 2 arguments, but 1 was provided
    constexpr span(_It __first, _End __last)
              ^
/home/runner/work/cmake-toolset/cmake-toolset/test/third_party/packages/opentelemetry-cpp-v1.8.1/sdk/src/metrics/meter_context.cc:53:10: error: no matching conversion for functional-style cast from 'std::vector<std::shared_ptr<CollectorHandle>>' to 'nostd::span<std::shared_ptr<CollectorHandle>>' (aka 'span<std::shared_ptr<opentelemetry::sdk::metrics::CollectorHandle>, 18446744073709551615UL>')
  return nostd::span<std::shared_ptr<CollectorHandle>>(collectors_);
         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/lib/llvm-14/bin/../include/c++/v1/span:401:15: note: candidate constructor not viable: no known conversion from 'std::vector<std::shared_ptr<CollectorHandle>>' to 'const std::span<std::shared_ptr<opentelemetry::sdk::metrics::CollectorHandle>, 18446744073709551615>' for 1st argument
    constexpr span           (const span&) noexcept = default;
              ^
/usr/lib/llvm-14/bin/../include/c++/v1/span:425:15: note: candidate template ignored: could not match 'type_identity_t<std::span<std::shared_ptr<opentelemetry::sdk::metrics::CollectorHandle>, 18446744073709551615>::element_type>[_Sz]' (aka 'std::shared_ptr<opentelemetry::sdk::metrics::CollectorHandle>[_Sz]') against 'std::vector<std::shared_ptr<CollectorHandle>>'
    constexpr span(type_identity_t<element_type> (&__arr)[_Sz]) noexcept : __data{__arr}, __size{_Sz} {}
              ^
/usr/lib/llvm-14/bin/../include/c++/v1/span:430:15: note: candidate template ignored: could not match 'array' against 'vector'
    constexpr span(array<_OtherElementType, _Sz>& __arr) noexcept : __data{__arr.data()}, __size{_Sz} {}
              ^
/usr/lib/llvm-14/bin/../include/c++/v1/span:435:15: note: candidate template ignored: could not match 'array' against 'vector'
    constexpr span(const array<_OtherElementType, _Sz>& __arr) noexcept : __data{__arr.data()}, __size{_Sz} {}
              ^
/usr/lib/llvm-14/bin/../include/c++/v1/span:445:19: note: candidate template ignored: could not match 'span' against 'vector'
        constexpr span(const span<_OtherElementType, _OtherExtent>& __other,
                  ^
/usr/lib/llvm-14/bin/../include/c++/v1/span:399:41: note: candidate constructor not viable: requires 0 arguments, but 1 was provided
    _LIBCPP_INLINE_VISIBILITY constexpr span() noexcept : __data{nullptr}, __size{0} {}
                                        ^
/usr/lib/llvm-14/bin/../include/c++/v1/span:410:15: note: candidate constructor template not viable: requires 2 arguments, but 1 was provided
    constexpr span(_It __first, size_type __count)
              ^
/usr/lib/llvm-14/bin/../include/c++/v1/span:419:15: note: candidate constructor template not viable: requires 2 arguments, but 1 was provided
    constexpr span(_It __first, _End __last)
              ^
[ 28%] Building CXX object sdk/src/trace/CMakeFiles/opentelemetry_trace.dir/tracer_context_factory.cc.o
1 warning and 2 errors generated.
gmake[2]: *** [sdk/src/metrics/CMakeFiles/opentelemetry_metrics.dir/build.make:118: sdk/src/metrics/CMakeFiles/opentelemetry_metrics.dir/meter_context.cc.o] Error 1
gmake[1]: *** [CMakeFiles/Makefile2:526: sdk/src/metrics/CMakeFiles/opentelemetry_metrics.dir/all] Error 2
gmake[1]: *** Waiting for unfinished jobs....
[ 29%] Building CXX object sdk/src/trace/CMakeFiles/opentelemetry_trace.dir/tracer_provider.cc.o
@owent owent added the bug Something isn't working label Dec 8, 2022
@owent owent self-assigned this Dec 8, 2022
@marcalff
Copy link
Member

marcalff commented Dec 8, 2022

Please take a look at:

Fix OTELCPP_MAINTAINER_MODE #1844

It builds with CLang 14, using CMake, using WITH_STL=ON.

@owent
Copy link
Member Author

owent commented Dec 8, 2022

Please take a look at:

Fix OTELCPP_MAINTAINER_MODE #1844

It builds with CLang 14, using CMake, using WITH_STL=ON.

I don't find -DWITH_STL=ON in cmake.maintainer.test of #1844 , and it do not use libc++ .
In my understanding, most clang on Linux do not compile with -DCLANG_DEFAULT_CXX_STDLIB=libc++ and will use libstdc++ by default.

@marcalff
Copy link
Member

marcalff commented Dec 8, 2022

Sorry, I thought cmake.maintainer.test was using WITH_STL=ON, but it turns out it does not.

Still, PR #1844 fixes some warnings related to nostd::span, and uses GOOGLETEST_VERSION as well, so there is some overlap here.

@owent
Copy link
Member Author

owent commented Dec 8, 2022

Sorry, I thought cmake.maintainer.test was using WITH_STL=ON, but it turns out it does not.

Still, PR #1844 fixes some warnings related to nostd::span, and uses GOOGLETEST_VERSION as well, so there is some overlap here.

I will merge #1844 into #1851 later.

Do you think we can upgrade the default version of googletest ? 1.10.0 use -Werror but 1.12.1 do not, and it may lead to more compiling error in the future if we built otlp-cpp on a new compiler in the future.

@owent
Copy link
Member Author

owent commented Dec 9, 2022

Sorry, I thought cmake.maintainer.test was using WITH_STL=ON, but it turns out it does not.
Still, PR #1844 fixes some warnings related to nostd::span, and uses GOOGLETEST_VERSION as well, so there is some overlap here.

I will merge #1844 into #1851 later.

Do you think we can upgrade the default version of googletest ? 1.10.0 use -Werror but 1.12.1 do not, and it may lead to more compiling error in the future if we built otlp-cpp on a new compiler in the future.

#1851 has merged the changes from #1844 now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants