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

dd-opentracing-cpp Win x64 - tracer.obj : error LNK2019: unresolved external symbol gethostname referenced in function "class datadog #266

Open
buzz3791 opened this issue Jul 17, 2023 · 2 comments

Comments

@buzz3791
Copy link

When adding the following to my C++ application
#include <opentracing/dynamic_load.h>

I'm getting the following when linking against dd_opentracing.lib

tracer.obj : error LNK2019: unresolved external symbol gethostname referenced in function "class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __cdecl datadog::opentracing::`anonymous namespace'::reportingHostname(struct
datadog::opentracing::TracerOptions)" (?reportingHostname@?A0x5ef9dd98@opentracing@datadog@@YA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@UTracerOptions@23@@Z) [C:\dev\ddog\dd-opentracing-cpp\.build\dd_opentracing.vcxproj]
C:\dev\ddog\dd-opentracing-cpp\.build\RelWithDebInfo\dd_opentracing.dll : fatal error LNK1120: 1 unresolved externals [C:\dev\ddog\dd-opentracing-cpp\.build\dd_opentracing.vcxproj]

DETAILS:

C:\dev\ddog\dd-opentracing-cpp\.build>cmake .. "-DCMAKE_TOOLCHAIN_FILE=c:\dev\vcpkg\scripts\buildsystems\vcpkg.cmake"
-- Running vcpkg install
Detecting compiler hash for triplet x64-windows...
All requested packages are currently installed.
Total install time: 300 ns
curl provides CMake targets:

    # this is heuristically generated, and may not be correct
    find_package(CURL CONFIG REQUIRED)
    target_link_libraries(main PRIVATE CURL::libcurl)

msgpack provides CMake targets:

    # this is heuristically generated, and may not be correct
    find_package(msgpack-cxx CONFIG REQUIRED)
    target_link_libraries(main PRIVATE msgpack-cxx)

opentracing provides CMake targets:

    # this is heuristically generated, and may not be correct
    find_package(OpenTracing CONFIG REQUIRED)
    target_link_libraries(main PRIVATE OpenTracing::opentracing OpenTracing::opentracing_mocktracer)

-- Running vcpkg install - done
-- Selecting Windows SDK version 10.0.19041.0 to target Windows 10.0.18363.
-- find_package(CURL CONFIG REQUIRED)
--   using share/curl/vcpkg-cmake-wrapper.cmake
--   find_package(ZLIB 1 REQUIRED)
--     using share/zlib/vcpkg-cmake-wrapper.cmake
-- find_package(Threads REQUIRED)
-- find_package(Sanitizers )
--   find_package(ASan )
--   find_package(TSan )
--   find_package(MSan )
--   find_package(UBSan )
-- Compiler ID: MSVC
-- Configuring done (5.9s)
-- Generating done (0.1s)
-- Build files have been written to: C:/dev/ddog/dd-opentracing-cpp/.build

C:\dev\ddog\dd-opentracing-cpp\.build>cmake --build . -- -p:Configuration=RelWithDebInfo
MSBuild version 17.4.0+18d5aef85 for .NET Framework
  agent_writer.cpp
  bool.cpp
  dynamic_load.cpp
  encoder.cpp
  glob.cpp
  limiter.cpp
C:\dev\ddog\dd-opentracing-cpp\src\limiter.cpp(71,32): warning C4244: '+=': conversion from '_Rep' to 'long', possible loss of data [C:\dev\ddog\dd-opentracing-cpp\.build\dd_opentracing.vcxproj]
          with
          [
              _Rep=__int64
          ]
  logger.cpp
C:\dev\ddog\dd-opentracing-cpp\src\logger.cpp(23,21): warning C4996: 'getenv': This function or variable may be unsafe. Consider using _dupenv_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details. [C:\dev\ddog\dd-open
tracing-cpp\.build\dd_opentracing.vcxproj]
  opentracing_agent.cpp
  opentracing_external.cpp
  parse_util.cpp
  pending_trace.cpp
  sample.cpp
  sampling_mechanism.cpp
  sampling_priority.cpp
  span.cpp
C:\dev\ddog\dd-opentracing-cpp\src\span.cpp(214,45): warning C4101: 'ia': unreferenced local variable [C:\dev\ddog\dd-opentracing-cpp\.build\dd_opentracing.vcxproj]
C:\dev\ddog\dd-opentracing-cpp\src\span.cpp(216,41): warning C4101: 'oor': unreferenced local variable [C:\dev\ddog\dd-opentracing-cpp\.build\dd_opentracing.vcxproj]
C:\dev\ddog\dd-opentracing-cpp\src\span.cpp(389,43): warning C4101: 'ia': unreferenced local variable [C:\dev\ddog\dd-opentracing-cpp\.build\dd_opentracing.vcxproj]
C:\dev\ddog\dd-opentracing-cpp\src\span.cpp(392,39): warning C4101: 'oor': unreferenced local variable [C:\dev\ddog\dd-opentracing-cpp\.build\dd_opentracing.vcxproj]
  span_buffer.cpp
  span_context.cpp
  tag_propagation.cpp
  tags.cpp
  trace_data.cpp
  Generating Code...
  Compiling...
  tracer.cpp
C:\dev\ddog\dd-opentracing-cpp\src\tracer.cpp(66,23): warning C4996: 'getenv': This function or variable may be unsafe. Consider using _dupenv_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details. [C:\dev\ddog\dd-open
tracing-cpp\.build\dd_opentracing.vcxproj]
C:\dev\ddog\dd-opentracing-cpp\src\tracer.cpp(94,27): warning C4996: 'getenv': This function or variable may be unsafe. Consider using _dupenv_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details. [C:\dev\ddog\dd-open
tracing-cpp\.build\dd_opentracing.vcxproj]
C:\dev\ddog\dd-opentracing-cpp\src\tracer.cpp(102,27): warning C4996: 'getenv': This function or variable may be unsafe. Consider using _dupenv_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details. [C:\dev\ddog\dd-ope
ntracing-cpp\.build\dd_opentracing.vcxproj]
C:\dev\ddog\dd-opentracing-cpp\src\tracer.cpp(117,38): warning C4996: 'getenv': This function or variable may be unsafe. Consider using _dupenv_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details. [C:\dev\ddog\dd-ope
ntracing-cpp\.build\dd_opentracing.vcxproj]
  tracer_factory.cpp
C:\dev\ddog\dd-opentracing-cpp\src\tracer_factory.cpp(8,19): warning C4273: '__p__environ': inconsistent dll linkage [C:\dev\ddog\dd-opentracing-cpp\.build\dd_opentracing.vcxproj]
C:\Program Files (x86)\Windows Kits\10\Include\10.0.19041.0\ucrt\stdlib.h(1158,29): message : see previous definition of '__p__environ' [C:\dev\ddog\dd-opentracing-cpp\.build\dd_opentracing.vcxproj]
  tracer_options.cpp
C:\dev\ddog\dd-opentracing-cpp\src\tracer_options.cpp(131,39): warning C4996: 'getenv': This function or variable may be unsafe. Consider using _dupenv_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details. [C:\dev\ddo
g\dd-opentracing-cpp\.build\dd_opentracing.vcxproj]
C:\dev\ddog\dd-opentracing-cpp\src\tracer_options.cpp(132,44): warning C4996: 'getenv': This function or variable may be unsafe. Consider using _dupenv_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details. [C:\dev\ddo
g\dd-opentracing-cpp\.build\dd_opentracing.vcxproj]
C:\dev\ddog\dd-opentracing-cpp\src\tracer_options.cpp(198,27): warning C4996: 'getenv': This function or variable may be unsafe. Consider using _dupenv_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details. [C:\dev\ddo
g\dd-opentracing-cpp\.build\dd_opentracing.vcxproj]
C:\dev\ddog\dd-opentracing-cpp\src\tracer_options.cpp(203,23): warning C4996: 'getenv': This function or variable may be unsafe. Consider using _dupenv_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details. [C:\dev\ddo
g\dd-opentracing-cpp\.build\dd_opentracing.vcxproj]
C:\dev\ddog\dd-opentracing-cpp\src\tracer_options.cpp(208,23): warning C4996: 'getenv': This function or variable may be unsafe. Consider using _dupenv_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details. [C:\dev\ddo
g\dd-opentracing-cpp\.build\dd_opentracing.vcxproj]
C:\dev\ddog\dd-opentracing-cpp\src\tracer_options.cpp(213,20): warning C4996: 'getenv': This function or variable may be unsafe. Consider using _dupenv_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details. [C:\dev\ddo
g\dd-opentracing-cpp\.build\dd_opentracing.vcxproj]
C:\dev\ddog\dd-opentracing-cpp\src\tracer_options.cpp(230,26): warning C4996: 'getenv': This function or variable may be unsafe. Consider using _dupenv_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details. [C:\dev\ddo
g\dd-opentracing-cpp\.build\dd_opentracing.vcxproj]
C:\dev\ddog\dd-opentracing-cpp\src\tracer_options.cpp(235,32): warning C4996: 'getenv': This function or variable may be unsafe. Consider using _dupenv_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details. [C:\dev\ddo
g\dd-opentracing-cpp\.build\dd_opentracing.vcxproj]
C:\dev\ddog\dd-opentracing-cpp\src\tracer_options.cpp(246,30): warning C4996: 'getenv': This function or variable may be unsafe. Consider using _dupenv_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details. [C:\dev\ddo
g\dd-opentracing-cpp\.build\dd_opentracing.vcxproj]
C:\dev\ddog\dd-opentracing-cpp\src\tracer_options.cpp(251,31): warning C4996: 'getenv': This function or variable may be unsafe. Consider using _dupenv_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details. [C:\dev\ddo
g\dd-opentracing-cpp\.build\dd_opentracing.vcxproj]
C:\dev\ddog\dd-opentracing-cpp\src\tracer_options.cpp(256,23): warning C4996: 'getenv': This function or variable may be unsafe. Consider using _dupenv_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details. [C:\dev\ddo
g\dd-opentracing-cpp\.build\dd_opentracing.vcxproj]
C:\dev\ddog\dd-opentracing-cpp\src\tracer_options.cpp(265,22): warning C4996: 'getenv': This function or variable may be unsafe. Consider using _dupenv_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details. [C:\dev\ddo
g\dd-opentracing-cpp\.build\dd_opentracing.vcxproj]
C:\dev\ddog\dd-opentracing-cpp\src\tracer_options.cpp(274,31): warning C4996: 'getenv': This function or variable may be unsafe. Consider using _dupenv_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details. [C:\dev\ddo
g\dd-opentracing-cpp\.build\dd_opentracing.vcxproj]
C:\dev\ddog\dd-opentracing-cpp\src\tracer_options.cpp(284,33): warning C4996: 'getenv': This function or variable may be unsafe. Consider using _dupenv_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details. [C:\dev\ddo
g\dd-opentracing-cpp\.build\dd_opentracing.vcxproj]
C:\dev\ddog\dd-opentracing-cpp\src\tracer_options.cpp(299,30): warning C4996: 'getenv': This function or variable may be unsafe. Consider using _dupenv_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details. [C:\dev\ddo
g\dd-opentracing-cpp\.build\dd_opentracing.vcxproj]
C:\dev\ddog\dd-opentracing-cpp\src\tracer_options.cpp(310,41): warning C4996: 'getenv': This function or variable may be unsafe. Consider using _dupenv_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details. [C:\dev\ddo
g\dd-opentracing-cpp\.build\dd_opentracing.vcxproj]
C:\dev\ddog\dd-opentracing-cpp\src\tracer_options.cpp(321,27): warning C4996: 'getenv': This function or variable may be unsafe. Consider using _dupenv_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details. [C:\dev\ddo
g\dd-opentracing-cpp\.build\dd_opentracing.vcxproj]
C:\dev\ddog\dd-opentracing-cpp\src\tracer_options.cpp(239,43): warning C4101: 'ia': unreferenced local variable [C:\dev\ddog\dd-opentracing-cpp\.build\dd_opentracing.vcxproj]
C:\dev\ddog\dd-opentracing-cpp\src\tracer_options.cpp(241,39): warning C4101: 'oor': unreferenced local variable [C:\dev\ddog\dd-opentracing-cpp\.build\dd_opentracing.vcxproj]
C:\dev\ddog\dd-opentracing-cpp\src\tracer_options.cpp(341,30): warning C4996: 'localtime': This function or variable may be unsafe. Consider using localtime_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details. [C:\de
v\ddog\dd-opentracing-cpp\.build\dd_opentracing.vcxproj]
  transport.cpp
C:\dev\ddog\dd-opentracing-cpp\src\transport.cpp(89,10): warning C4996: 'strncpy': This function or variable may be unsafe. Consider using strncpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details. [C:\dev\ddog\dd-
opentracing-cpp\.build\dd_opentracing.vcxproj]
  version.cpp
  writer.cpp
  Generating Code...
     Creating library C:/dev/ddog/dd-opentracing-cpp/.build/RelWithDebInfo/dd_opentracing.lib and object C:/dev/ddog/dd-opentracing-cpp/.build/RelWithDebInfo/dd_opentracing.exp
tracer.obj : error LNK2019: unresolved external symbol gethostname referenced in function "class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __cdecl datadog::opentracing::`anonymous namespace'::reportingHostname(struct
datadog::opentracing::TracerOptions)" (?reportingHostname@?A0x5ef9dd98@opentracing@datadog@@YA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@UTracerOptions@23@@Z) [C:\dev\ddog\dd-opentracing-cpp\.build\dd_opentracing.vcxproj]
C:\dev\ddog\dd-opentracing-cpp\.build\RelWithDebInfo\dd_opentracing.dll : fatal error LNK1120: 1 unresolved externals [C:\dev\ddog\dd-opentracing-cpp\.build\dd_opentracing.vcxproj]

C:\dev\ddog\dd-opentracing-cpp\.build>
@buzz3791
Copy link
Author

I worked around this issue with these changes:

PS C:\dev\ddog\dd-opentracing-cpp> git diff .\CMakeLists.txt                                                            diff --git a/CMakeLists.txt b/CMakeLists.txt
index fc121ca..3f602bb 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -64,7 +64,7 @@ endif()
 if(BUILD_COVERAGE)
   set(COVERAGE_LIBRARIES gcov)
 endif()
-set(DATADOG_LINK_LIBRARIES ${OPENTRACING_LIB} ${CURL_LIBRARIES} Threads::Threads ${COVERAGE_LIBRARIES})
+set(DATADOG_LINK_LIBRARIES ws2_32 ${OPENTRACING_LIB} ${CURL_LIBRARIES} Threads::Threads ${COVERAGE_LIBRARIES})

 ## Shared lib
 if(BUILD_SHARED)
@@ -97,7 +97,7 @@ endif()
 if(BUILD_OBJECT)
   add_library(dd_opentracing-object OBJECT ${DD_OPENTRACING_SOURCES})
   add_sanitizers(dd_opentracing-object)
-  target_link_libraries(dd_opentracing-object ${CURL_LIBRARIES} Threads::Threads)
+  target_link_libraries(dd_opentracing-object ws2_32 ${CURL_LIBRARIES} Threads::Threads)
   set_property(TARGET dd_opentracing-object PROPERTY POSITION_INDEPENDENT_CODE ON)
   target_compile_definitions(dd_opentracing-object PUBLIC DD_OPENTRACING_OBJECT)
 endif()
PS C:\dev\ddog\dd-opentracing-cpp>

@dgoffredo
Copy link
Contributor

Thanks, @buzz3791. See my comment in #265 (comment).

Let's leave both of these open for reference.

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

2 participants