I'm having issues with what appears to be a nostd:: std:: clash in libraries under ubuntu 22. opentelemetry-cpp was configured with:
cmake -DBUILD_TESTING=OFF -DWITH_EXAMPLES=OFF -DCMAKE_POSITION_INDEPENDENT_CODE=ON -DBUILD_SHARED_LIBS=ON -DWITH_OTLP_HTTP=ON -DWITH_OTLP_GRPC=ON -DWITH_ABI_VERSION_1=OFF -DWITH_ABI_VERSION_2=ON -DWITH_STL=ON -DCMAKE_CXX_STANDARD=17 ..
this built successfully. The test app uses a otlp grpc log exporter, and the problem seems to be that the application wants the 1st parameter to LoggerProvider::GetLogger to be opentelemetry::v2::nostd::string_view, while libopentelemetry_logs.so shows a std::basic_string_view for the first parameter. (see make and nm output below)
$ make
g++ otel_test.o -L/home/mandrews/downloads/github/opentelemetry-cpp/build/exporters/otlp -lopentelemetry_common -L/home/mandrews/downloads/github/opentelemetry-cpp/build/sdk/src/common -lopentelemetry_exporter_otlp_grpc -lopentelemetry_exporter_otlp_grpc_client -lopentelemetry_exporter_otlp_grpc_log -lopentelemetry_exporter_otlp_http_log -L/home/mandrews/downloads/github/opentelemetry-cpp/build/sdk/src/logs -lopentelemetry_logs -L/home/mandrews/downloads/github/opentelemetry-cpp/build/sdk/src/trace -lopentelemetry_trace -L/home/mandrews/downloads/github/opentelemetry-cpp/build/_deps/grpc-build/third_party/protobuf -lprotobuf -o otel_test
/usr/bin/ld: otel_test.o: in function `main':
/home/mandrews/dev/otel_test.cpp:41: undefined reference to `opentelemetry::v2::sdk::logs::LoggerProvider::GetLogger(opentelemetry::v2::nostd::string_view, opentelemetry::v2::nostd::string_view, opentelemetry::v2::nostd::string_view, opentelemetry::v2::nostd::string_view, opentelemetry::v2::common::KeyValueIterable const&)'
collect2: error: ld returned 1 exit status
make: *** [Makefile:45: otel_test] Error 1
$ nm ./sdk/src/logs/libopentelemetry_logs.so | grep GetLogger
00000000001ff854 T _ZN13opentelemetry2v23sdk4logs14LoggerProvider9GetLoggerESt17basic_string_viewIcSt11char_traitsIcEES7_S7_S7_RKNS0_6common16KeyValueIterableE
00000000001fc8ea W _ZN13opentelemetry2v24logs18NoopLoggerProvider9GetLoggerESt17basic_string_viewIcSt11char_traitsIcEES6_S6_S6_RKNS0_6common16KeyValueIterableE
00000000002499b4 T _ZNK13opentelemetry2v23sdk4logs13LoggerContext21GetLoggerConfiguratorEv
How did the app get the idea it should want the nostd:: version ? Don't know how to fix this...
here is the Makefile:
oteldir=/home/mandrews/downloads/github/opentelemetry-cpp
otellibdir=$(oteldir)/build
appanalysisdir=$(projectdir)/app_analysis
zlibdir=$(thirdpartydir)/zlib
module_defs= -D_LINUX -DOPENTELEMETRY_ABI_VERSION_NO=2
sources=\
otel_test.cpp
objects=$(sources:.cpp=.o)
cppflags=\
-std=c++20 \
-fno-omit-frame-pointer \
-fpermissive \
-Wno-unused-local-typedefs \
$(module_defs) \
-I. \
-I$(oteldir)/ext/include \
-I$(oteldir)/api/include \
-I$(oteldir)/sdk/include \
-I$(oteldir)/exporters/otlp/include
ldflags=\
-L$(otellibdir)/exporters/otlp -lopentelemetry_common \
-L$(otellibdir)/sdk/src/common -lopentelemetry_exporter_otlp_grpc -lopentelemetry_exporter_otlp_grpc_client \
-lopentelemetry_exporter_otlp_grpc_log -lopentelemetry_exporter_otlp_http_log \
-L$(otellibdir)/sdk/src/logs -lopentelemetry_logs \
-L$(otellibdir)/sdk/src/trace -lopentelemetry_trace \
-L$(otellibdir)/_deps/grpc-build/third_party/protobuf -lprotobuf
ifeq ($(BUILD),DEBUG)
cppflags += -ggdb3 -O0 -D_DEBUG
else
cppflags += -g -Wall -O2 -DNDEBUG
endif
executable=otel_test
all: $(executable)
otel_test: $(objects)
g++ $^ $(ldflags) -o $@
%.o: %.cpp
g++ $(cppflags) -c -o $@ $<
clean:
rm -f $(objects)
rm -f $(executable)
what to do to compile successfully?
It's expected that you use cmake and target_link_libraries()
that would bring the required compiler definitions to the target. Since you don't use cmake, you must add -DOPENTELEMETRY_STL_VERSION=2017
to cppflags
:
cppflags += -DOPENTELEMETRY_STL_VERSION=2017
BTW, -DWITH_STL=ON -DCMAKE_CXX_STANDARD=17
are inconsistent: the first one defines OPENTELEMETRY_STL_VERSION=2023
, but the compiler standard is set to C++17. -DWITH_STL=CXX17 -DCMAKE_CXX_STANDARD=17
should be passed.