Skip to content
This repository has been archived by the owner on Jan 26, 2024. It is now read-only.

OpenTracing in Vcpkg #105

Open
david-antiteum opened this issue Apr 8, 2019 · 9 comments
Open

OpenTracing in Vcpkg #105

david-antiteum opened this issue Apr 8, 2019 · 9 comments

Comments

@david-antiteum
Copy link
Contributor

More than an issue an announcement :)

I have added OpenTracing to vcpkg (C++ Library Manager) repository via this merged PR: microsoft/vcpkg#5974

It works in Windows and Linux (probably in macOS but vcpkg doesn't run in macOS yet).

During the porting I have found two problems:

  • no UWP support (not important)
  • cannot build the static version without the dynamic one (so vcpkg builds either the dynamic version or the static AND dynamic version)

Install the package with:

vcpkg install opentracing

Then use it in cmake (dynamic version):

find_package(OpenTracing CONFIG REQUIRED)
target_link_libraries(main PRIVATE OpenTracing::opentracing)

or (static version):

find_package(OpenTracing CONFIG REQUIRED)
target_link_libraries(main PRIVATE OpenTracing::opentracing-static)
@rnburn
Copy link
Contributor

rnburn commented Apr 8, 2019

Did you try building with cmake -DBUILD_SHARED_LIBS=OFF? -- that should produce only the static library.

@david-antiteum
Copy link
Contributor Author

Yes, I tried that.

Using this command:

vcpkg install opentracing --triplet x64-windows-static

That does this definitions in a modified portfile

-DBUILD_SHARED_LIBS=OFF
-DBUILD_STATIC_LIBS=ON
-DBUILD_MOCKTRACER=OFF
-DBUILD_DYNAMIC_LOADING=OFF

I got this errors (same with BUILD_DYNAMIC_LOADING=ON):

tracer_test.cpp.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) class std::error_category const & __cdecl opentracing::v2::propagation_error_category(void)" (__imp_?propagation_error_category@v2@opentracing@@YAAEBVerror_category@std@@XZ) referenced in function "void __cdecl opentracing::v2::`dynamic initializer for 'invalid_carrier_error''(void)" (??__Einvalid_carrier_error@v2@opentracing@@YAXXZ)
tracer_test.cpp.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: class std::unique_ptr<class opentracing::v2::Span,struct std::default_delete<class opentracing::v2::Span> > __cdecl opentracing::v2::Tracer::StartSpan(class opentracing::v2::string_view,class std::initializer_list<class opentracing::v2::option_wrapper<class opentracing::v2::StartSpanOption> >)const " (__imp_?StartSpan@Tracer@v2@opentracing@@QEBA?AV?$unique_ptr@VSpan@v2@opentracing@@U?$default_delete@VSpan@v2@opentracing@@@std@@@std@@Vstring_view@23@V?$initializer_list@V?$option_wrapper@VStartSpanOption@v2@opentracing@@@v2@opentracing@@@5@@Z) referenced in function "void __cdecl ____C_A_T_C_H____T_E_S_T____0(void)" (?____C_A_T_C_H____T_E_S_T____0@@YAXXZ)
tracer_test.cpp.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) class std::shared_ptr<class opentracing::v2::Tracer> __cdecl opentracing::v2::MakeNoopTracer(void)" (__imp_?MakeNoopTracer@v2@opentracing@@YA?AV?$shared_ptr@VTracer@v2@opentracing@@@std@@XZ) referenced in function "void __cdecl ____C_A_T_C_H____T_E_S_T____0(void)" (?____C_A_T_C_H____T_E_S_T____0@@YAXXZ)
tracer_test.cpp.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) class opentracing::v2::string_view const opentracing::v2::ext::span_kind" (__imp_?span_kind@ext@v2@opentracing@@3Vstring_view@23@B)
tracer_test.cpp.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) class opentracing::v2::string_view const opentracing::v2::ext::span_kind_rpc_client" (__imp_?span_kind_rpc_client@ext@v2@opentracing@@3Vstring_view@23@B)

Using -DBUILD_STATIC_LIBS=OFF works fine for dynamic only builds.

Thanks,

@rnburn
Copy link
Contributor

rnburn commented Apr 10, 2019

My guess is it has something to do with this OPENTRACING_API macro applied before the variable declarations.

Could you investigate to see if it should be set to something else for static builds? I'm not very familiar with building for windows.

cc @mdouaihy

@david-antiteum
Copy link
Contributor Author

I will...

@david-antiteum
Copy link
Contributor Author

Found the problem. The CMakeLists.txt in mocktracer/test needs OPENTRACING_MOCK_TRACER_STATIC. I will open an PR.

rnburn pushed a commit that referenced this issue Apr 22, 2019
* compile mocktracer test using static lib #105

* PUBLIC was enough #105
@david-antiteum
Copy link
Contributor Author

I will wait for a OpenTracing release to modify the vcpkg portfile. If you don't mind I will keep this case open as a remainder :)

@mdouaihy
Copy link
Contributor

sorry for my late comment.

Note that linking statically OpenTracing can cause unexpected behavior: The Global Tracer will be defined in each library/binary linking statically with OpenTracing.

@david-antiteum
Copy link
Contributor Author

The current settings in vcpkg allows the compilation of shared and shared and static versions. The changes in the PR was to solve a problem in the CMakefiles.txt that prevents the static building alone. But, if static has no sense, then better just disable it, either in this project or in the vcpkg repo.

Just let me know...

@mdouaihy
Copy link
Contributor

Static causes problems only for the Global Tracer only on Windows. Maybe the user isn't using the Global Tracer.

@rnburn, do you think the static build should be prevented for that reason?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants