-
Notifications
You must be signed in to change notification settings - Fork 442
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
undefined reference to `opentelemetry::v1::sdk::common #1359
Comments
You should not create imported target yourself, please use |
@ccoqueiro - Let us know if @owent suggestion fixes the issue, and good to close it. |
Hello owent!! Thank you for your suggestion. I set up as suggested, but returned a warning message when performing the build with cmake and returned an error while performing make. cmake -DCMAKE_PREFIX_PATH=/opt/otelcpp/ .. IMPORTED_LOCATION not set for imported target CMake Warning (dev) in CMakeLists.txt: IMPORTED_LOCATION not set for imported target CMake Warning (dev) in CMakeLists.txt: IMPORTED_LOCATION not set for imported target CMake Warning (dev) in CMakeLists.txt: IMPORTED_LOCATION not set for imported target CMake Warning (dev) in CMakeLists.txt: IMPORTED_LOCATION not set for imported target CMake Warning (dev) in CMakeLists.txt: IMPORTED_LOCATION not set for imported target "opentelemetry-cpp::metrics". -- Generating done My CMakeList.txt cmake_minimum_required(VERSION 3.23) find_package(Protobuf REQUIRED) message(STATUS "otel c++ include dirs: ${OPENTELEMETRY_CPP_INCLUDE_DIRS}") add_library(libopentelemetry_proto STATIC IMPORTED) set_target_properties(libt PROPERTIES add_executable(hello-otel main.cpp) target_include_directories(hello-otel PRIVATE ${OPENTELEMETRY_CPP_INCLUDE_DIRS}) |
@ccoqueiro cmake_minimum_required(VERSION 3.23)
project(otel-test)
find_package(Thrift REQUIRED)
find_package(opentelemetry-cpp CONFIG REQUIRED)
message(STATUS "otel c++ include dirs: ${OPENTELEMETRY_CPP_INCLUDE_DIRS}")
message(STATUS "otel c++ libs: ${OPENTELEMETRY_CPP_LIBRARIES}")
message(STATUS "thrift libs: ${THRIFT_FOUND_LIB}")
add_executable(hello-otel main.cpp)
target_link_libraries(hello-otel opentelemetry-cpp::ostream_span_exporter opentelemetry-cpp::jaeger_trace_exporter opentelemetry-cpp::otlp_grpc_exporter opentelemetry-cpp::otlp_grpc_log_exporter opentelemetry-cpp::otlp_http_exporter opentelemetry-cpp::metrics opentelemetry-cpp::sdk) BTW: You can use |
@ccoqueiro - Just wondering if you still have issue after @owent suggestion above ? |
Hello All, Thank you @owent for suggestion, I applied this suggestion, but fail again, incredible. If I try to run with the command "cmake --build ." I got the error: root@LabC:/opt/helloworld/build# cmake --build . If try to run with the command: "cmake .. -DCMAKE_PREFIX_PATH=/opt/otelcpp/". I got the warnings and the error: root@LabC:/opt/helloworld/build# cmake .. -DCMAKE_PREFIX_PATH=/opt/otelcpp/ IMPORTED_LOCATION not set for imported target CMake Warning (dev) in CMakeLists.txt: IMPORTED_LOCATION not set for imported target CMake Warning (dev) in CMakeLists.txt: IMPORTED_LOCATION not set for imported target CMake Warning (dev) in CMakeLists.txt: IMPORTED_LOCATION not set for imported target CMake Warning (dev) in CMakeLists.txt: IMPORTED_LOCATION not set for imported target "opentelemetry-cpp::metrics". -- Generating done |
Both below build errors seem not opentelemetry-cpp specific. @ccoqueiro, can you clear the build folder and re-run both
|
This problem may be the same as #705 . Could you please provide your cmake_minimum_required(VERSION 3.23)
project(otel-test)
find_package(Protobuf REQUIRED)
find_package(nlohmann_json REQUIRED)
find_package(CURL REQUIRED)
find_package(gRPC REQUIRED)
find_package(Thrift REQUIRED)
find_package(absl REQUIRED)
find_package(opentelemetry-cpp CONFIG REQUIRED)
# ============ Patch IMPORTED_VARS BEGIN ============
function(project_build_tools_patch_default_imported_config)
set(PATCH_VARS
IMPORTED_IMPLIB
IMPORTED_LIBNAME
IMPORTED_LINK_DEPENDENT_LIBRARIES
IMPORTED_LINK_INTERFACE_LANGUAGES
IMPORTED_LINK_INTERFACE_LIBRARIES
IMPORTED_LINK_INTERFACE_MULTIPLICITY
IMPORTED_LOCATION
IMPORTED_NO_SONAME
IMPORTED_OBJECTS
IMPORTED_SONAME)
foreach(TARGET_NAME ${ARGN})
if(TARGET ${TARGET_NAME})
get_target_property(IS_IMPORTED_TARGET ${TARGET_NAME} IMPORTED)
if(NOT IS_IMPORTED_TARGET)
continue()
endif()
if(CMAKE_VERSION VERSION_LESS "3.19.0")
get_target_property(TARGET_TYPE_NAME ${TARGET_NAME} TYPE)
if(TARGET_TYPE_NAME STREQUAL "INTERFACE_LIBRARY")
continue()
endif()
endif()
get_target_property(DO_NOT_OVERWRITE ${TARGET_NAME} IMPORTED_LOCATION)
if(DO_NOT_OVERWRITE)
continue()
endif()
if(CMAKE_VERSION VERSION_LESS "3.19.0")
get_target_property(TARGET_TYPE_NAME ${TARGET_NAME} TYPE)
if(TARGET_TYPE_NAME STREQUAL "INTERFACE_LIBRARY")
continue()
endif()
endif()
# MSVC's STL and debug level must match the target, so we can only move out IMPORTED_LOCATION_NOCONFIG
if(MSVC)
set(PATCH_IMPORTED_CONFIGURATION "NOCONFIG")
else()
get_target_property(PATCH_IMPORTED_CONFIGURATION ${TARGET_NAME} IMPORTED_CONFIGURATIONS)
endif()
if(NOT PATCH_IMPORTED_CONFIGURATION)
continue()
endif()
get_target_property(PATCH_TARGET_LOCATION ${TARGET_NAME} "IMPORTED_LOCATION_${PATCH_IMPORTED_CONFIGURATION}")
if(NOT PATCH_TARGET_LOCATION)
continue()
endif()
foreach(PATCH_IMPORTED_KEY IN LISTS PATCH_VARS)
get_target_property(PATCH_IMPORTED_VALUE ${TARGET_NAME} "${PATCH_IMPORTED_KEY}_${PATCH_IMPORTED_CONFIGURATION}")
if(PATCH_IMPORTED_VALUE)
set_target_properties(${TARGET_NAME} PROPERTIES "${PATCH_IMPORTED_KEY}" "${PATCH_IMPORTED_VALUE}")
endif()
endforeach()
endif()
endforeach()
endfunction()
set(THIRD_PARTY_OPENTELEMETRY_CPP_LINK_NAMES ${OPENTELEMETRY_CPP_LIBRARIES})
set(_IMPLICIT_OPENTELEMETRY_CPP_TARGETS opentelemetry-cpp::resources opentelemetry-cpp::proto
opentelemetry-cpp::otlp_recordable)
foreach(_IMPLICIT_OPENTELEMETRY_CPP_TARGET IN LISTS _IMPLICIT_OPENTELEMETRY_CPP_TARGETS)
if(TARGET ${_IMPLICIT_OPENTELEMETRY_CPP_TARGET}
AND NOT ${_IMPLICIT_OPENTELEMETRY_CPP_TARGET} IN_LIST
THIRD_PARTY_OPENTELEMETRY_CPP_LINK_NAMES)
list(APPEND THIRD_PARTY_OPENTELEMETRY_CPP_LINK_NAMES
${_IMPLICIT_OPENTELEMETRY_CPP_TARGET})
endif()
endforeach()
unset(_IMPLICIT_OPENTELEMETRY_CPP_TARGET)
unset(_IMPLICIT_OPENTELEMETRY_CPP_TARGETS)
project_build_tools_patch_default_imported_config(CURL::libcurl
prometheus-cpp::core prometheus-cpp::pull prometheus-cpp::push
civetweb::civetweb-cpp civetweb::civetweb)
project_build_tools_patch_default_imported_config(
${THIRD_PARTY_OPENTELEMETRY_CPP_LINK_NAMES})
# ------------ Patch IMPORTED_VARS END ------------
message(STATUS "otel c++ include dirs: ${OPENTELEMETRY_CPP_INCLUDE_DIRS}")
message(STATUS "otel c++ libs: ${OPENTELEMETRY_CPP_LIBRARIES}")
message(STATUS "thrift libs: ${THRIFT_FOUND_LIB}")
add_executable(hello-otel main.cpp)
target_link_libraries(hello-otel opentelemetry-cpp::ostream_span_exporter opentelemetry-cpp::jaeger_trace_exporter opentelemetry-cpp::otlp_grpc_exporter opentelemetry-cpp::otlp_grpc_log_exporter opentelemetry-cpp::otlp_http_exporter opentelemetry-cpp::metrics opentelemetry-cpp::sdk) |
Hello @ThomsonTan ! Sure, I cleaned the builder folder and re-run the command cmake .., I got the error: root@LabC:/opt/helloworld/build# cmake ..
but the target was not found. Possible reasons include:
Call Stack (most recent call first): CMake Error at /usr/local/lib/cmake/opentelemetry-cpp/opentelemetry-cpp-target.cmake:63 (set_target_properties):
but the target was not found. Possible reasons include:
Call Stack (most recent call first): CMake Error at /usr/local/lib/cmake/opentelemetry-cpp/opentelemetry-cpp-target.cmake:121 (set_target_properties):
but the target was not found. Possible reasons include:
Call Stack (most recent call first): CMake Error at /usr/local/lib/cmake/opentelemetry-cpp/opentelemetry-cpp-target.cmake:143 (set_target_properties):
but the target was not found. Possible reasons include:
Call Stack (most recent call first): CMake Error at /usr/local/lib/cmake/opentelemetry-cpp/opentelemetry-cpp-target.cmake:150 (set_target_properties):
but the target was not found. Possible reasons include:
Call Stack (most recent call first): CMake Error at /usr/local/lib/cmake/opentelemetry-cpp/opentelemetry-cpp-target.cmake:157 (set_target_properties):
but the target was not found. Possible reasons include:
Call Stack (most recent call first): -- Generating done I never really thought that building a simple hello world was something close to the impossible :-( |
Sorry for my mistake. The depended libraries need find_package(Protobuf REQUIRED)
find_package(nlohmann_json REQUIRED)
find_package(CURL REQUIRED)
find_package(gRPC REQUIRED)
find_package(Thrift REQUIRED)
find_package(absl REQUIRED)
find_package(opentelemetry-cpp CONFIG REQUIRED) And maybe we also need patch some of these packages. project_build_tools_patch_default_imported_config(CURL::libcurl
prometheus-cpp::core prometheus-cpp::pull prometheus-cpp::push
civetweb::civetweb-cpp civetweb::civetweb) I have update the |
Hello @owent !! Thank you so much!! Almost there, command cmake .. now runs without errors or warnings: root@LabC:/opt/helloworld/build# cmake .. But when I ran the command cmake --build . I got this error: root@LabC:/opt/helloworld/build# cmake --build . |
When you build opentelemetry with vcpkg. it's required to load toolchain of that vcpkg when run cmake. @lalitb @ThomsonTan Should we document this when we use internal submodule of vcpkg? |
Hello @owent !! Finally compiled the code and generated the executeable without errors or warnings, super thank you, I have no words that can express my gratitude, |
Yes, I think it is good idea to document this in INSTALL.md under cmake build section. |
I suggest to add a FAQ section to collect these problems.In my experience, the problems in this issue do not always happen, it depends how to use cmake and the version and cmake. |
Ok, my bad. I thought you meant documenting how to use |
Besides adding the doc, could we add some check to our CMake list file, like if otel-cpp is built with vcpkg, the user import it should also use vcpkg (with the toolchain file specified)? |
Good idea. |
Hello All, I thank you too much for the support of all of you, after a month trying to compile a simple C++ code, I was able to compile with the information you passed here, this last parameter was last(cmake .. -DCMAKE_TOOLCHAIN_FILE=/root/source/opentelemetry-cpp/tools/vcpkg/scripts/buildsystems/vcpkg.cmake .), through it I managed to compile the code, next step is now to try to generate a trace, which will be the subject of another discussion. Thank you so much again |
Hi Everyone,
A few days ago I'm trying to compile a simple hello world application(cpp), after the saga of the compilation of opentelemetry cpp SDK, I'm having the following error when running make:
/usr/bin/ld: /opt/otelcpp/lib/libopentelemetry_trace.a(random_id_generator.cc.o): in function
opentelemetry::v1::sdk::trace::RandomIdGenerator::GenerateSpanId()': random_id_generator.cc:(.text+0x41): undefined reference to
opentelemetry::v1::sdk::common::Random::GenerateRandomBuffer(opentelemetry::v1::nostd::span<unsigned char, 18446744073709551615ul>)'/usr/bin/ld: /opt/otelcpp/lib/libopentelemetry_trace.a(random_id_generator.cc.o): in function
opentelemetry::v1::sdk::trace::RandomIdGenerator::GenerateTraceId()': random_id_generator.cc:(.text+0xc7): undefined reference to
opentelemetry::v1::sdk::common::Random::GenerateRandomBuffer(opentelemetry::v1::nostd::span<unsigned char, 18446744073709551615ul>)'/usr/bin/ld: /opt/otelcpp/lib/libopentelemetry_exporter_jaeger_trace.a(THttpTransport.cc.o): in function
opentelemetry::v1::exporter::jaeger::THttpTransport::THttpTransport(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::multimap<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, opentelemetry::v1::ext::http::client::cmp_ic, std::allocator<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> > > > >)': THttpTransport.cc:(.text+0xb6): undefined reference to
opentelemetry::v1::ext::http::client::HttpClientFactory::CreateSync()'collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/hello-otel.dir/build.make:113: hello-otel] Error 1
make[1]: *** [CMakeFiles/Makefile2:83: CMakeFiles/hello-otel.dir/all] Error 2
make: *** [Makefile:91: all] Error 2
My CMakeList.txt:
cmake_minimum_required(VERSION 3.23)
project(otel-test)
find_package(Protobuf REQUIRED)
find_package(nlohmann_json REQUIRED)
find_package(CURL REQUIRED)
find_package(gRPC REQUIRED)
find_package(Thrift REQUIRED)
find_package(absl REQUIRED)
find_package(opentelemetry-cpp CONFIG REQUIRED)
message(STATUS "otel c++ include dirs: ${OPENTELEMETRY_CPP_INCLUDE_DIRS}")
message(STATUS "otel c++ libs: ${OPENTELEMETRY_CPP_LIBRARIES}")
message(STATUS "thrift libs: ${THRIFT_FOUND_LIB}")
add_library(libopentelemetry_common STATIC IMPORTED)
add_library(libopentelemetry_resources STATIC IMPORTED)
add_library(libopentelemetry_trace STATIC IMPORTED)
add_library(libopentelemetry_version STATIC IMPORTED)
add_library(libopentelemetry_metrics STATIC IMPORTED)
add_library(libopentelemetry_http_client_curl STATIC IMPORTED)
add_library(lib_client_nosend STATIC IMPORTED)
add_library(libopentelemetry_otlp_recordable STATIC IMPORTED)
add_library(libopentelemetry_exporter_otlp_grpc_log STATIC IMPORTED)
add_library(libopentelemetry_exporter_otlp_http_client STATIC IMPORTED)
add_library(libopentelemetry_exporter_otlp_http STATIC IMPORTED)
add_library(libopentelemetry_exporter_otlp_grpc STATIC IMPORTED)
add_library(libopentelemetry_exporter_ostream_span STATIC IMPORTED)
add_library(libopentelemetry_exporter_jaeger_trace STATIC IMPORTED)
add_library(libt STATIC IMPORTED)
set_target_properties(libt PROPERTIES
IMPORTED_LOCATION "/usr/local/lib/libthrift.a"
)
set_target_properties(libopentelemetry_common PROPERTIES
IMPORTED_LOCATION "/opt/otelcpp/lib/libopentelemetry_common.a"
)
set_target_properties(libopentelemetry_resources PROPERTIES
IMPORTED_LOCATION "/opt/otelcpp/lib/libopentelemetry_resources.a"
)
set_target_properties(libopentelemetry_trace PROPERTIES
IMPORTED_LOCATION "/opt/otelcpp/lib/libopentelemetry_trace.a"
)
set_target_properties(libopentelemetry_version PROPERTIES
IMPORTED_LOCATION "/opt/otelcpp/lib/libopentelemetry_version.a"
)
set_target_properties(libopentelemetry_metrics PROPERTIES
IMPORTED_LOCATION "/opt/otelcpp/lib/libopentelemetry_metrics.a"
)
set_target_properties(libopentelemetry_http_client_curl PROPERTIES
IMPORTED_LOCATION "/opt/otelcpp/lib/libopentelemetry_http_client_curl.a"
)
set_target_properties(lib_client_nosend PROPERTIES
IMPORTED_LOCATION "/opt/otelcpp/lib/libhttp_client_nosend.a"
)
set_target_properties(libopentelemetry_http_client_curl PROPERTIES
IMPORTED_LOCATION "/opt/otelcpp/lib/libopentelemetry_http_client_curl.a"
)
set_target_properties(lib_client_nosend PROPERTIES
IMPORTED_LOCATION "/opt/otelcpp/lib/libhttp_client_nosend.a"
)
set_target_properties(libopentelemetry_otlp_recordable PROPERTIES
IMPORTED_LOCATION "/opt/otelcpp/lib/libopentelemetry_otlp_recordable.a"
)
set_target_properties(libopentelemetry_exporter_otlp_grpc_log PROPERTIES
IMPORTED_LOCATION "/opt/otelcpp/lib/libopentelemetry_exporter_otlp_grpc_log.a"
)
set_target_properties(libopentelemetry_exporter_otlp_http_client PROPERTIES
IMPORTED_LOCATION "/opt/otelcpp/lib/libopentelemetry_exporter_otlp_http_client.a"
)
set_target_properties(libopentelemetry_exporter_otlp_http PROPERTIES
IMPORTED_LOCATION "/opt/otelcpp/lib/libopentelemetry_exporter_otlp_http.a"
)
set_target_properties(libopentelemetry_exporter_otlp_grpc PROPERTIES
IMPORTED_LOCATION "/opt/otelcpp/lib/libopentelemetry_exporter_otlp_grpc.a"
)
set_target_properties(libopentelemetry_exporter_ostream_span PROPERTIES
IMPORTED_LOCATION "/opt/otelcpp/lib/libopentelemetry_exporter_ostream_span.a"
)
set_target_properties(libopentelemetry_exporter_jaeger_trace PROPERTIES
IMPORTED_LOCATION "/opt/otelcpp/lib/libopentelemetry_exporter_jaeger_trace.a"
)
add_executable(hello-otel main.cpp)
target_include_directories(hello-otel PRIVATE ${OPENTELEMETRY_CPP_INCLUDE_DIRS})
target_link_libraries(hello-otel libopentelemetry_common libopentelemetry_resources libopentelemetry_trace
libopentelemetry_version libopentelemetry_metrics libopentelemetry_http_client_curl
lib_client_nosend libopentelemetry_otlp_recordable libopentelemetry_exporter_otlp_grpc_log
libopentelemetry_exporter_otlp_grpc_log libopentelemetry_exporter_otlp_http_client libopentelemetry_exporter_otlp_http
libopentelemetry_exporter_otlp_grpc libopentelemetry_exporter_ostream_span libopentelemetry_exporter_jaeger_trace
libt)
Command to build:
cmake -DCMAKE_PREFIX_PATH=/opt/otelcpp/ ..
Output of command to build:
cmake -DCMAKE_PREFIX_PATH=/opt/otelcpp/ ..
-- The C compiler identification is GNU 9.4.0
-- The CXX compiler identification is GNU 9.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
-- Found Protobuf: /usr/local/lib/libprotobuf.so;-lpthread (found version "3.19.2")
-- Found nlohmann_json: /opt/otelcpp/lib/cmake/nlohmann_json/nlohmann_jsonConfig.cmake (found version "3.9.1")
-- Found CURL: /opt/vcpkg/installed/x64-linux/share/curl/CURLConfig.cmake (found version "7.82.0-DEV")
-- Found Threads: TRUE
-- Found thrift: /root/source/opentelemetry-cpp/tools/vcpkg
-- Found opentelemetry-cpp: /opt/otelcpp/include
-- otel c++ include dirs: /opt/otelcpp/include
-- otel c++ libs: opentelemetry-cpp::api;opentelemetry-cpp::sdk;opentelemetry-cpp::ext;opentelemetry-cpp::version;opentelemetry-cpp::common;opentelemetry-cpp::trace;opentelemetry-cpp::metrics;opentelemetry-cpp::in_memory_span_exporter;opentelemetry-cpp::otlp_recordable;opentelemetry-cpp::otlp_grpc_exporter;opentelemetry-cpp::otlp_http_client;opentelemetry-cpp::otlp_http_exporter;opentelemetry-cpp::ostream_span_exporter;opentelemetry-cpp::jaeger_trace_exporter;opentelemetry-cpp::http_client_curl
-- thrift libs:
-- Configuring done
-- Generating done
-- Build files have been written to: /opt/helloworld/build
Thank you in advance :-)
The text was updated successfully, but these errors were encountered: