jupp0r / prometheus-cpp

Prometheus Client Library for Modern C++
Other
924 stars 326 forks source link

build error `bin/prometheus_push_internal_test` with ubuntu 20.04 and 22.04 #687

Closed fujitatomoya closed 8 months ago

fujitatomoya commented 8 months ago

It used to be no problem to build with ubuntu 20.04 on master branch, but now we have been meeting with the following build error.

root@tomoyafujita:~/docker_ws/SRT/prometheus-cpp/_build# make -j 4
Scanning dependencies of target gmock_main
Scanning dependencies of target civetweb
Scanning dependencies of target core
...<snip>
[ 90%] Linking CXX executable ../../../bin/prometheus_push_internal_test
/usr/bin/ld: CMakeFiles/prometheus_push_internal_test.dir/label_encoder_test.cc.o: in function `prometheus::(anonymous namespace)::LabelEncoderTest::Encode(std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > const&)':
label_encoder_test.cc:(.text+0x58): undefined reference to `prometheus::detail::encodeLabel(std::ostream&, std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > const&)'
collect2: error: ld returned 1 exit status
make[2]: *** [push/tests/internal/CMakeFiles/prometheus_push_internal_test.dir/build.make:87: bin/prometheus_push_internal_test] Error 1
make[1]: *** [CMakeFiles/Makefile2:703: push/tests/internal/CMakeFiles/prometheus_push_internal_test.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs....
[ 91%] Building CXX object core/tests/CMakeFiles/prometheus_core_test.dir/registry_test.cc.o
[ 93%] Building CXX object core/tests/CMakeFiles/prometheus_core_test.dir/serializer_test.cc.o
[ 95%] Building CXX object core/tests/CMakeFiles/prometheus_core_test.dir/summary_test.cc.o
[ 96%] Building CXX object core/tests/CMakeFiles/prometheus_core_test.dir/text_serializer_test.cc.o
[ 98%] Building CXX object core/tests/CMakeFiles/prometheus_core_test.dir/utils_test.cc.o
[100%] Linking CXX executable ../../bin/prometheus_core_test
[100%] Built target prometheus_core_test
make: *** [Makefile:163: all] Error 2

related issue: https://github.com/Haivision/srt-prometheus-exporter/issues/25

gjasny commented 8 months ago

Could you please share your cmake configure command and the output of it?

fujitatomoya commented 8 months ago

@gjasny thanks for checking on this.

root@tomoyafujita:~/docker_ws/SRT/prometheus-cpp# git submodule update
Cloning into '/root/docker_ws/SRT/prometheus-cpp/3rdparty/civetweb'...
Cloning into '/root/docker_ws/SRT/prometheus-cpp/3rdparty/googletest'...
Submodule path '3rdparty/civetweb': checked out 'd7ba35bbb649209c66e582d5a0244ba988a15159'
Submodule path '3rdparty/googletest': checked out 'e2239ee6043f73722e7aa812a459f54a28552929'
root@tomoyafujita:~/docker_ws/SRT/prometheus-cpp# mkdir _build
root@tomoyafujita:~/docker_ws/SRT/prometheus-cpp# cd _build
root@tomoyafujita:~/docker_ws/SRT/prometheus-cpp/_build# cmake .. -DBUILD_SHARED_LIBS=ON
-- The C compiler identification is GNU 11.4.0
-- The CXX compiler identification is GNU 11.4.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Success
-- Found Threads: TRUE  
-- Performing Test HAVE_CXX_ATOMICS_WITHOUT_LIB
-- Performing Test HAVE_CXX_ATOMICS_WITHOUT_LIB - Success
-- Could NOT find benchmark (missing: benchmark_DIR)
-- Performing Test COMPILER_HAS_HIDDEN_VISIBILITY
-- Performing Test COMPILER_HAS_HIDDEN_VISIBILITY - Success
-- Performing Test COMPILER_HAS_HIDDEN_INLINE_VISIBILITY
-- Performing Test COMPILER_HAS_HIDDEN_INLINE_VISIBILITY - Success
-- Performing Test COMPILER_HAS_DEPRECATED_ATTR
-- Performing Test COMPILER_HAS_DEPRECATED_ATTR - Success
-- Found ZLIB: /usr/lib/x86_64-linux-gnu/libz.so (found version "1.2.11") 
-- Found CURL: /usr/lib/x86_64-linux-gnu/libcurl.so (found version "7.81.0")  
-- The following features have been enabled:

 * Pull, support for pulling metrics
 * Push, support for pushing metrics to a push-gateway
 * Compression, support for zlib compression of metrics
 * pkg-config, generate pkg-config files

-- The following REQUIRED packages have been found:

 * googlemock-3rdparty
 * civetweb-3rdparty
 * ZLIB
 * CURL

-- The following features have been disabled:

 * IYWU, include-what-you-use

-- The following OPTIONAL packages have not been found:

 * benchmark

-- Configuring done
-- Generating done
-- Build files have been written to: /root/docker_ws/SRT/prometheus-cpp/_build
root@tomoyafujita:~/docker_ws/SRT/prometheus-cpp/_build# make -j 4
[  5%] Building CXX object pull/CMakeFiles/civetweb.dir/__/3rdparty/civetweb/src/CivetServer.cpp.o
[  5%] Building CXX object CMakeFiles/gmock_main.dir/3rdparty/googletest/googletest/src/gtest-all.cc.o
[  5%] Building CXX object core/CMakeFiles/core.dir/src/check_names.cc.o
[  6%] Building CXX object CMakeFiles/gmock_main.dir/3rdparty/googletest/googlemock/src/gmock-all.cc.o
[  8%] Building CXX object core/CMakeFiles/core.dir/src/counter.cc.o
[ 10%] Building CXX object core/CMakeFiles/core.dir/src/detail/builder.cc.o
[ 11%] Building C object pull/CMakeFiles/civetweb.dir/__/3rdparty/civetweb/src/civetweb.c.o
[ 13%] Building CXX object core/CMakeFiles/core.dir/src/detail/ckms_quantiles.cc.o
[ 13%] Built target civetweb
[ 15%] Building CXX object CMakeFiles/gmock_main.dir/3rdparty/googletest/googlemock/src/gmock_main.cc.o
[ 16%] Building CXX object core/CMakeFiles/core.dir/src/detail/time_window_quantiles.cc.o
[ 18%] Building CXX object core/CMakeFiles/core.dir/src/detail/utils.cc.o
[ 20%] Building CXX object core/CMakeFiles/core.dir/src/family.cc.o
[ 21%] Building CXX object core/CMakeFiles/core.dir/src/gauge.cc.o
[ 23%] Building CXX object core/CMakeFiles/core.dir/src/histogram.cc.o
[ 25%] Building CXX object core/CMakeFiles/core.dir/src/info.cc.o
[ 26%] Building CXX object core/CMakeFiles/core.dir/src/registry.cc.o
[ 28%] Building CXX object core/CMakeFiles/core.dir/src/serializer.cc.o
[ 30%] Building CXX object core/CMakeFiles/core.dir/src/summary.cc.o
[ 31%] Building CXX object core/CMakeFiles/core.dir/src/text_serializer.cc.o
[ 33%] Linking CXX static library lib/libgmock_main.a
[ 33%] Built target gmock_main
[ 35%] Building CXX object util/tests/unit/CMakeFiles/prometheus_util_test.dir/base64_test.cc.o
[ 36%] Linking CXX shared library ../lib/libprometheus-cpp-core.so
[ 36%] Built target core
[ 41%] Building CXX object push/CMakeFiles/push.dir/src/gateway.cc.o
[ 41%] Building CXX object core/tests/CMakeFiles/prometheus_core_test.dir/builder_test.cc.o
[ 41%] Building CXX object pull/CMakeFiles/pull.dir/src/basic_auth.cc.o
[ 43%] Building CXX object pull/CMakeFiles/pull.dir/src/endpoint.cc.o
[ 45%] Linking CXX executable ../../../bin/prometheus_util_test
[ 45%] Built target prometheus_util_test
[ 46%] Building CXX object push/CMakeFiles/push.dir/src/detail/curl_wrapper.cc.o
[ 48%] Building CXX object pull/CMakeFiles/pull.dir/src/exposer.cc.o
[ 50%] Building CXX object push/CMakeFiles/push.dir/src/detail/label_encoder.cc.o
[ 51%] Building CXX object pull/CMakeFiles/pull.dir/src/handler.cc.o
[ 53%] Building CXX object pull/CMakeFiles/pull.dir/src/metrics_collector.cc.o
[ 55%] Linking CXX shared library ../lib/libprometheus-cpp-push.so
[ 55%] Built target push
[ 56%] Building CXX object core/tests/CMakeFiles/prometheus_core_test.dir/check_label_name_test.cc.o
[ 58%] Building CXX object push/tests/integration/CMakeFiles/sample_client.dir/sample_client.cc.o
[ 60%] Building CXX object core/tests/CMakeFiles/prometheus_core_test.dir/check_metric_name_test.cc.o
[ 61%] Linking CXX shared library ../lib/libprometheus-cpp-pull.so
[ 61%] Built target pull
[ 63%] Building CXX object push/tests/internal/CMakeFiles/prometheus_push_internal_test.dir/label_encoder_test.cc.o
[ 65%] Linking CXX executable ../../../bin/sample_client
[ 66%] Building CXX object core/tests/CMakeFiles/prometheus_core_test.dir/counter_test.cc.o
[ 66%] Built target sample_client
[ 68%] Building CXX object core/tests/CMakeFiles/prometheus_core_test.dir/family_test.cc.o
[ 70%] Building CXX object core/tests/CMakeFiles/prometheus_core_test.dir/gauge_test.cc.o
[ 71%] Linking CXX executable ../../../bin/prometheus_push_internal_test
/usr/bin/ld: CMakeFiles/prometheus_push_internal_test.dir/label_encoder_test.cc.o: in function `prometheus::(anonymous namespace)::LabelEncoderTest::Encode(std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > const&)':
label_encoder_test.cc:(.text+0x58): undefined reference to `prometheus::detail::encodeLabel(std::ostream&, std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > const&)'
collect2: error: ld returned 1 exit status
make[2]: *** [push/tests/internal/CMakeFiles/prometheus_push_internal_test.dir/build.make:100: bin/prometheus_push_internal_test] Error 1
make[1]: *** [CMakeFiles/Makefile2:658: push/tests/internal/CMakeFiles/prometheus_push_internal_test.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs....
[ 73%] Building CXX object core/tests/CMakeFiles/prometheus_core_test.dir/histogram_test.cc.o
[ 75%] Building CXX object core/tests/CMakeFiles/prometheus_core_test.dir/registry_test.cc.o
[ 76%] Building CXX object core/tests/CMakeFiles/prometheus_core_test.dir/serializer_test.cc.o
[ 78%] Building CXX object core/tests/CMakeFiles/prometheus_core_test.dir/summary_test.cc.o
[ 80%] Building CXX object core/tests/CMakeFiles/prometheus_core_test.dir/text_serializer_test.cc.o
[ 81%] Building CXX object core/tests/CMakeFiles/prometheus_core_test.dir/utils_test.cc.o
[ 83%] Linking CXX executable ../../bin/prometheus_core_test
[ 83%] Built target prometheus_core_test
make: *** [Makefile:166: all] Error 2
Jeff9699 commented 8 months ago

Issue occurs because libprometheus-cpp-push.so is created with symbol encodeLabel hidden (-fvisibility=hidden). Program _label_encodertest attempts to link that symbol.

Solution, in existing form, is to allow default visibility of symbol encodeLabel. E.g. in push/src/detail/label_encoder.h void encodeLabel(std::ostream& os, const Label& label) __attribute__ ((visibility ("default")));

fujitatomoya commented 8 months ago

because libprometheus-cpp-push.so is created with symbol encodeLabel hidden

true, it has been hidden for a long time. not sure which commit generates this problem though.

https://github.com/jupp0r/prometheus-cpp/blob/master/CMakeLists.txt#L52-L57

Solution, in existing form, is to allow default visibility of symbol encodeLabel.

yeah, that would be a short path we can take here.

https://github.com/jupp0r/prometheus-cpp/pull/689

or, probably we can reconsider this implementation needs to be in detail? that i was not really sure.

fujitatomoya commented 8 months ago

@gjasny thanks, i will try that out on my side if anything up, i will let you know.