-
Notifications
You must be signed in to change notification settings - Fork 334
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
linker error while compiling example cpp program #695
Comments
This is not about example programs but when source code is configured with [ 98%] Linking CXX executable ../../../bin/prometheus_push_internal_test
cd /home/tkloczko/rpmbuild/BUILD/prometheus-cpp-1.2.1/x86_64-redhat-linux-gnu/push/tests/internal && /usr/bin/cmake -E cmake_link_script CMakeFiles/prometheus_push_internal_test.dir/link.txt --verbose=1
/usr/bin/g++ -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -O2 -g -grecord-gcc-switches -pipe -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer -fdata-sections -ffunction-sections -fstack-protector-strong -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -flto=auto -Wp,-U_FORTIFY_SOURCE,-D_FORTIFY_SOURCE=3 -Wp,-D_GLIBCXX_ASSERTIONS -Wall -Werror=format-security -fno-rtti -DNDEBUG -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -Wl,--gc-sections -Wl,--as-needed -Wl,--build-id=sha1 -Wl,-z,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -Wl,-z,pack-relative-relocs -flto=auto -fuse-linker-plugin CMakeFiles/prometheus_push_internal_test.dir/label_encoder_test.cc.o -o ../../../bin/prometheus_push_internal_test -Wl,-rpath,/home/tkloczko/rpmbuild/BUILD/prometheus-cpp-1.2.1/x86_64-redhat-linux-gnu/lib /usr/lib64/libgmock_main.so.1.14.0 ../../../lib/libprometheus-cpp-push.so.1.2.0 ../../../lib/libprometheus-cpp-core.so.1.2.0 /usr/lib64/libgmock.so.1.14.0 /usr/lib64/libgtest.so.1.14.0
/usr/bin/ld: /tmp/ccepa2St.ltrans0.ltrans.o: in function `prometheus::(anonymous namespace)::LabelEncoderTest_unicode_Test::TestBody()':
/home/tkloczko/rpmbuild/BUILD/prometheus-cpp-1.2.1/push/tests/internal/label_encoder_test.cc:15:(.text._ZN10prometheus12_GLOBAL__N_129LabelEncoderTest_unicode_Test8TestBodyEv+0x274): 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&)'
/usr/bin/ld: /tmp/ccepa2St.ltrans0.ltrans.o: in function `prometheus::(anonymous namespace)::LabelEncoderTest_path_Test::TestBody()':
/home/tkloczko/rpmbuild/BUILD/prometheus-cpp-1.2.1/push/tests/internal/label_encoder_test.cc:15:(.text._ZN10prometheus12_GLOBAL__N_126LabelEncoderTest_path_Test8TestBodyEv+0x237): 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&)'
/usr/bin/ld: /tmp/ccepa2St.ltrans0.ltrans.o: in function `prometheus::(anonymous namespace)::LabelEncoderTest_empty_Test::TestBody()':
/home/tkloczko/rpmbuild/BUILD/prometheus-cpp-1.2.1/push/tests/internal/label_encoder_test.cc:15:(.text._ZN10prometheus12_GLOBAL__N_127LabelEncoderTest_empty_Test8TestBodyEv+0x226): 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&)'
/usr/bin/ld: /tmp/ccepa2St.ltrans0.ltrans.o: in function `prometheus::(anonymous namespace)::LabelEncoderTest_regular_Test::TestBody()':
/home/tkloczko/rpmbuild/BUILD/prometheus-cpp-1.2.1/push/tests/internal/label_encoder_test.cc:15:(.text._ZN10prometheus12_GLOBAL__N_129LabelEncoderTest_regular_Test8TestBodyEv+0x239): 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:105: bin/prometheus_push_internal_test] Error 1 |
In my case I had disabled the testing -DENABLE_TESTING=OFF and the source got compiled well and has generated the libs, not sure why the example code is not able to compile and displaying undefined reference error |
But this is nothing more than just swiping dust under the carpet 😋 |
@captKBK could you please run:
to see the defined symbols? Your |
Did you try the latest 1.2.1 version? |
Hi @gjasny Here is the output, [root@localhost cppApp]# nm -C /root/prometheus_poc/prometheus_libs/lib64/libprometheus-cpp-pull.so | grep 'Exposer::Exposer' |
If you will look one more time on output which I've provided you can find that it was generated on building exactly that version. |
@captKBK It looks like your Theoretically the error will vanish if you run:
|
Are you using GCC 11 from devtoolset-11? |
I'm using devel snapshot of the gcc 14,x which is now available in fedora rawhide. |
@kloczek and your distribution is also fedora rawhide? |
@kloczek Please test v1.2.2. I forgot to release a new version with the build fix. Sorry about that. |
Just tested 1.2.2 and now all looks good and it passes test suite as well😄 + cd prometheus-cpp-1.2.2
+ /usr/bin/ctest --test-dir x86_64-redhat-linux-gnu --output-on-failure --force-new-ctest-process -j48
Internal ctest changing into directory: /home/tkloczko/rpmbuild/BUILD/prometheus-cpp-1.2.2/x86_64-redhat-linux-gnu
Test project /home/tkloczko/rpmbuild/BUILD/prometheus-cpp-1.2.2/x86_64-redhat-linux-gnu
Start 1: prometheus_core_test
Start 2: prometheus_util_test
Start 3: prometheus_pull_integration_test
Start 4: prometheus_pull_test
Start 5: prometheus_push_internal_test
1/5 Test #2: prometheus_util_test ............... Passed 0.01 sec
2/5 Test #5: prometheus_push_internal_test ...... Passed 0.01 sec
3/5 Test #1: prometheus_core_test ............... Passed 1.30 sec
4/5 Test #4: prometheus_pull_test ............... Passed 2.01 sec
5/5 Test #3: prometheus_pull_integration_test ... Passed 28.12 sec
100% tests passed, 0 tests failed out of 5
Thing happens .. you don't need to say sorry as your rection was instant 😋 Thank you very much👍 |
@gjasny No I have compiled it from source on my machine |
Almost 100% in case of most of the packages however I'm still I need to finish clean gcc so this is why I'm using gcc from rawhide. |
@captKBK you probably compiled prometheus-cpp with a different compiler than you used for your |
@gjasny Yes that worked, I found root cause, gcc 4.8 was still existing in my machine and while compiling prometheus-cpp it was considering gcc 4.8 and not 11.2, I removed it and recompiled the prometheus-cpp source, it worked fine. Thanks for the help! |
Hi,
I am facing an issue while compiling the example cpp program(under this section: https://github.com/jupp0r/prometheus-cpp/tree/v1.0.1?tab=readme-ov-file#usage),
I am using v1.0.1, c++11, CentOS 7.9, GCC 11.2.0
I have used "-lprometheus-cpp-pull -lprometheus-cpp-core -lz" but still getting undefined reference error for Exposer methods.
Error for reference:
->cmd line command:
g++ -std=c++11 -o prom.exe test_prometheus.cpp -I/root/prometheus_poc/prometheus_libs/include -L/root/prometheus_poc/prometheus_libs/lib64/ -lprometheus-cpp-pull -lprometheus-cpp-core -lz
Error:
/tmp/ccXC71MO.o: In function
main': test_prometheus.cpp:(.text+0x77): undefined reference to
prometheus::Exposer::Exposer(std::__cxx11::basic_string<char, std::char_traits, std::allocator > const&, unsigned long, CivetCallbacks const*)'test_prometheus.cpp:(.text+0xf6): undefined reference to
prometheus::detail::Builder<prometheus::Counter>::Name(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)' test_prometheus.cpp:(.text+0x135): undefined reference to
prometheus::detail::Builderprometheus::Counter::Help(std::__cxx11::basic_string<char, std::char_traits, std::allocator > const&)'test_prometheus.cpp:(.text+0x5b6): undefined reference to
prometheus::detail::Builder<prometheus::Counter>::Name(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)' test_prometheus.cpp:(.text+0x5f5): undefined reference to
prometheus::detail::Builderprometheus::Counter::Help(std::__cxx11::basic_string<char, std::char_traits, std::allocator > const&)'test_prometheus.cpp:(.text+0x6c4): undefined reference to
prometheus::Exposer::RegisterCollectable(std::weak_ptr<prometheus::Collectable> const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)' /tmp/ccXC71MO.o: In function
prometheus::Counter& prometheus::Familyprometheus::Counter::Add<>(std::map<std::__cxx11::basic_string<char, std::char_traits, std::allocator >, std::__cxx11::basic_string<char, std::char_traits, std::allocator >, std::less<std::__cxx11::basic_string<char, std::char_traits, std::allocator > >, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits, std::allocator > const, std::__cxx11::basic_string<char, std::char_traits, std::allocator > > > > const&)':test_prometheus.cpp:(.text.ZN10prometheus6FamilyINS_7CounterEE3AddIJEEERS1_RKSt3mapINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESB_St4lessISB_ESaISt4pairIKSB_SB_EEEDpOT[ZN10prometheus6FamilyINS_7CounterEE3AddIJEEERS1_RKSt3mapINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESB_St4lessISB_ESaISt4pairIKSB_SB_EEEDpOT]+0x30): undefined reference to `prometheus::Familyprometheus::Counter::Add(std::map<std::__cxx11::basic_string<char, std::char_traits, std::allocator >, std::__cxx11::basic_string<char, std::char_traits, std::allocator >, std::less<std::__cxx11::basic_string<char, std::char_traits, std::allocator > >, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits, std::allocator > const, std::__cxx11::basic_string<char, std::char_traits, std::allocator > > > > const&, std::unique_ptr<prometheus::Counter, std::default_deleteprometheus::Counter >)'
collect2: error: ld returned 1 exit status
The text was updated successfully, but these errors were encountered: