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

Getting undefined reference to `opentelemetry::v0::sdk::resource::Resource::Create while all libraries are there #618

Closed
ghost opened this issue Mar 19, 2021 · 6 comments

Comments

@ghost
Copy link

ghost commented Mar 19, 2021

Hi,

I have compiled the opentelemetry-cpp libraries as shared and installed them on Ubuntu 18.04.

Unfortunately I did not find yet why I get the following error when I am trying to compile my library against them:

undefined reference to opentelemetry::v0::sdk::resource::Resource::Create(std::unordered_map<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, opentelemetry::v0::nostd::variant<bool, int, unsigned int, long, unsigned long, double, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::vector<bool, std::allocator<bool> >, std::vector<int, std::allocator<int> >, std::vector<unsigned int, std::allocator<unsigned int> >, std::vector<long, std::allocator<long> >, std::vector<unsigned long, std::allocator<unsigned long> >, std::vector<double, std::allocator<double> >, std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >, std::hash<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::equal_to<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, opentelemetry::v0::nostd::variant<bool, int, unsigned int, long, unsigned long, double, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::vector<bool, std::allocator<bool> >, std::vector<int, std::allocator<int> >, std::vector<unsigned int, std::allocator<unsigned int> >, std::vector<long, std::allocator<long> >, std::vector<unsigned long, std::allocator<unsigned long> >, std::vector<double, std::allocator<double> >, std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > > > > > const&)

The symbol seems to be in place:

nm -gDC libopentelemetry_resources.so | grep Create
0000000000007820 T opentelemetry::v0::sdk::resource::Resource::Create(std::unordered_map<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::variant<bool, int, unsigned int, long, unsigned long, double, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::vector<bool, std::allocator<bool> >, std::vector<int, std::allocator<int> >, std::vector<unsigned int, std::allocator<unsigned int> >, std::vector<long, std::allocator<long> >, std::vector<unsigned long, std::allocator<unsigned long> >, std::vector<double, std::allocator<double> >, std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >, std::hash<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::equal_to<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, std::variant<bool, int, unsigned int, long, unsigned long, double, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::vector<bool, std::allocator<bool> >, std::vector<int, std::allocator<int> >, std::vector<unsigned int, std::allocator<unsigned int> >, std::vector<long, std::allocator<long> >, std::vector<unsigned long, std::allocator<unsigned long> >, std::vector<double, std::allocator<double> >, std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > > > > > const&)
@lalitb
Copy link
Member

lalitb commented Mar 19, 2021

Works for me - this is link error, so please ensure you are passing this library as link option to compiler/linker:

$ ls /usr/local/lib/libopentelemetry_resources.so
/usr/local/lib/libopentelemetry_resources.so
$ g++ ./resource_test.cpp
/usr/bin/ld: /tmp/ccVGz9Id.o: in function `main':
resource_test.cpp:(.text+0x160): undefined reference to `opentelemetry::v0::sdk::resource::Resource::Create(std::unordered_map<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, opentelemetry::v0::nostd::variant<bool, int, unsigned int, long, unsigned long, double, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::vector<bool, std::allocator<bool> >, std::vector<int, std::allocator<int> >, std::vector<unsigned int, std::allocator<unsigned int> >, std::vector<long, std::allocator<long> >, std::vector<unsigned long, std::allocator<unsigned long> >, std::vector<double, std::allocator<double> >, std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >, std::hash<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::equal_to<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, opentelemetry::v0::nostd::variant<bool, int, unsigned int, long, unsigned long, double, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::vector<bool, std::allocator<bool> >, std::vector<int, std::allocator<int> >, std::vector<unsigned int, std::allocator<unsigned int> >, std::vector<long, std::allocator<long> >, std::vector<unsigned long, std::allocator<unsigned long> >, std::vector<double, std::allocator<double> >, std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > > > > > const&)'
collect2: error: ld returned 1 exit status
$ g++ ./resource_test.cpp -lopentelemetry_resources
$ ldd ./a.out
        linux-vdso.so.1 (0x00007ffe971c5000)
        libopentelemetry_resources.so => /usr/local/lib/libopentelemetry_resources.so (0x00007f6aa8bd8000)
        libstdc++.so.6 => /lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f6aa89e7000)
        libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f6aa89cc000)
        libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f6aa87da000)
        libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f6aa868b000)
        /lib64/ld-linux-x86-64.so.2 (0x00007f6aa8ccc000)
$

@ghost
Copy link
Author

ghost commented Mar 19, 2021

Works for me - this is link error, so please ensure you are passing this library as link option to compiler/linker:

labhas@MININT-47CLAOB:/tmp$ ls /usr/local/lib/libopentelemetry_resources.so
/usr/local/lib/libopentelemetry_resources.so
labhas@MININT-47CLAOB:/tmp$ g++ ./resource_test.cpp
/usr/bin/ld: /tmp/ccVGz9Id.o: in function `main':
resource_test.cpp:(.text+0x160): undefined reference to `opentelemetry::v0::sdk::resource::Resource::Create(std::unordered_map<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, opentelemetry::v0::nostd::variant<bool, int, unsigned int, long, unsigned long, double, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::vector<bool, std::allocator<bool> >, std::vector<int, std::allocator<int> >, std::vector<unsigned int, std::allocator<unsigned int> >, std::vector<long, std::allocator<long> >, std::vector<unsigned long, std::allocator<unsigned long> >, std::vector<double, std::allocator<double> >, std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >, std::hash<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::equal_to<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, opentelemetry::v0::nostd::variant<bool, int, unsigned int, long, unsigned long, double, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::vector<bool, std::allocator<bool> >, std::vector<int, std::allocator<int> >, std::vector<unsigned int, std::allocator<unsigned int> >, std::vector<long, std::allocator<long> >, std::vector<unsigned long, std::allocator<unsigned long> >, std::vector<double, std::allocator<double> >, std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > > > > > const&)'
collect2: error: ld returned 1 exit status
labhas@MININT-47CLAOB:/tmp$ g++ ./resource_test.cpp -lopentelemetry_resources
labhas@MININT-47CLAOB:/tmp$

Thank you very much for the reply. I compared the actual symbol missing and the actual symbol in the library it seems to be related to WITH_STL cmake definition.

My library is looking for opentelemetry::v0::nostd::variant for example but the opentelemetry_resources library was compiled with the -DWITH_STL=ON and it uses std::variant` for a parameter type. Same goes for other parameters as well.

The library is in the path alright. Thanks again!

@lalitb
Copy link
Member

lalitb commented Mar 19, 2021

Good catch. As you are trying Resource API, just to let you know - the necessary sdk changes to inject resources to exporters are not yet complete, and under review (#580) for some design discussions. You may want to revisit it in couple of weeks if you want to try out that.

@ghost
Copy link
Author

ghost commented Mar 19, 2021

Right now I am getting a POC ready for distributed tracing with OpenTelemetry and the ELK Stack. If that works I am OK for now. I understand the libraries are under development.

Awesome stuff here. I am sure it will help us a lot understand the performance.

@ghost
Copy link
Author

ghost commented Mar 19, 2021

I turned off WITH_STL and it did compile in the end just fine; but in order to compile it with STL I had to add the following definitions in my CMakeLists.txt:

add_definitions(-DHAVE_CPP_STDLIB -DHAVE_GSL)

because the headers under /usr/local/include/opentelemetry are depending on them.

Since the types to be used are configured with CMake and the binaries include the correct types, this tells me a library using the opentelemetry headers should not require these definitions (-DHAVE_CPP_STDLIB -DHAVE_GSL) but instead the types included in the installed opentelemetry headers should match the types compiled inside the installed opentelemetry binaries.

@ghost
Copy link
Author

ghost commented Mar 22, 2021

@lalitb thanks for the help really! I am closing this

@ghost ghost closed this as completed Mar 22, 2021
This issue was closed.
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

No branches or pull requests

1 participant