0

I have a c++ program which using Jaeger for tracing

#include <iostream>
#include<memory>
#include <yaml-cpp/yaml.h>
// #include <opentracing/tracer.h>
#include<jaegertracing/Tracer.h>

namespace std
{

void init(const char *FilePath)
{
    auto yaml = YAML::LoadFile(FilePath);
    auto config = jaegertracing::Config::parse(yaml);
    auto tracer=jaegertracing::Tracer::make(
        "example-service",
        config,
        jaegertracing::logging::consoleLogger()
    );
    opentracing::Tracer::InitGlobal(
        static_pointer_cast<opentracing::Tracer>(tracer)
    );
}

void ChildSpan(const unique_ptr<opentracing::Span>& parentSpan){
    this_thread::sleep_for(1ms);
    auto childSpan = opentracing::Tracer::Global()->StartSpan("Span2",{opentracing::ChildOf(&parentSpan->context())});
}

void FollowsSpan(const unique_ptr<opentracing::Span>& followFromspan){
    this_thread::sleep_for(2ms);
    auto followSpan = opentracing::Tracer::Global()->StartSpan("Span3",{opentracing::FollowsFrom(&followFromspan->context())});
}

void ParentSpan(){
    auto span = opentracing::Tracer::Global()->StartSpan("Span1");
    ChildSpan(span);
    FollowsSpan(span);
    this_thread::sleep_for(3ms);
}

int main()
{
    init("./config.yaml");
    ParentSpan();
    return 0;
}
}

I compile it using g++ -std=c++1z test.cpp -I /usr/local/lib/ -ljaegertracing -lyaml-cpp where /usr/local/lib/libyaml-cpp.a is the installation path.

Error message -

/usr/bin/ld: warning: libyaml-cppd.so.0.6, needed by //usr/local/lib/libjaegertracing.so, not found (try using -rpath or -rpath-link)
/usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/Scrt1.o: In function `_start':
(.text+0x20): undefined reference to `main'
collect2: error: ld returned 1 exit status

I have installed yaml-cpp-0.6.0 by downloading source code .tar version did mkdir build,cd build,sudo make,sudo make install

I dont know why my compilation is failing.

I have libyaml-cppd.so.0.6 in yaml-cpp/build directory and tried this path to compile but still it is failing.

OS - ubuntu 18.04

Abhinav Singh
  • 302
  • 3
  • 15

2 Answers2

1

-I is used for include paths. Use -L for library paths:

g++ -std=c++1z test.cpp -L /usr/local/lib -ljaegertracing -lyaml-cpp

It also looks like you've linked with a shared library libyaml-cppd.so - not the static library libyaml-cpp.a. I don't recognize the d in libyaml-cppd.so though. I'd check if that's really the library you built.

libyaml-cpp will be built as a static library by default (libyaml-cpp.a) and on a 64 bit machine, it will probably default to being installed in /usr/local/lib64.


You are only allowed to do very limited things in namespace std. Adding new functions/classes are not allowed (unless as template specializations including user defined types) - so remove namespace std { ... } around your program.

Also. the main function should be in the global namespace. The reason it's not found by the linker is because you put it in a namespace (std).

UPDATE : The issue is resolved follow this link exaclty https://github.com/jaegertracing/jaeger-client-cpp/issues/162#issuecomment-565892473 (use thrift version 0.11 or 0.11+)

Abhinav Singh
  • 302
  • 3
  • 15
Ted Lyngmo
  • 93,841
  • 5
  • 60
  • 108
  • not working, it is particularly demanding `libyaml-cppd.so.0.6` this library but it is no where to be found. – Abhinav Singh Mar 01 '20 at 04:55
  • now some strange thing is happening when I m reinstalling the from source it is not building l`ibyaml-cpp.so.0.6` but only the `libyaml-cpp.a.`. I cannot understand why is this happening – Abhinav Singh Mar 01 '20 at 06:18
  • 1
    @AbhinavSingh Did you get the latest source from github perhaps? It makes the static library by default. Is the jaeger library pre-built to link with `yaml-cpp` btw.? If so, the location and version number of `yaml-cpp` must match perfectly. I have no idea why it wants the name `libyaml-cppd.so` with a `d` in it though. – Ted Lyngmo Mar 01 '20 at 10:58
  • no,I m using master branch of yaml-cpp as source code,I think I m getting there, I will update whaterver happens. – Abhinav Singh Mar 01 '20 at 11:01
  • @AbhinavSingh Didn't you build libyaml from a `0.6.0` tar ball? If you get `yaml-cpp` from github you'll get `0.6.3` + bugfixes. – Ted Lyngmo Mar 01 '20 at 11:03
  • 1
    the tar version was creating some more erros other than linking when compiling, so swicthed to github ones ,its master branch is default to 0.6.3. I have found a link which I think is similar to my problem https://github.com/jaegertracing/jaeger-client-cpp/issues/162#issuecomment-565892473 I hope this helps me :) – Abhinav Singh Mar 01 '20 at 11:12
0

As well as linking with -I instead of the correct -L (as mentioned by Ted Lyngmo)

g++ -std=c++1z test.cpp -L /usr/local/lib -ljaegertracing -lyaml-cpp

I wanted to address the "d" in libyaml-cppd.so As seen in the yaml-cpp CMakeLists.txt found here (line 136) a "d" is added as a POSTFIX when compiling for debugging purposes.

if (NOT DEFINED CMAKE_DEBUG_POSTFIX)
  set(CMAKE_DEBUG_POSTFIX "d")
endif()

All you need to do is set the CMAKE_DEBUG_POSTFIX to whatever you want while compiling the yaml-cpp library. When set as an empty string, it will remove the "d" from your library binary.

Through CMakeLists.txt you can just do:

set(CMAKE_DEBUG_POSTFIX "")

If you are compiling directly add this as a cmake argument: -DCMAKE_DEBUG_POSTFIX=""

Kikadass
  • 314
  • 1
  • 3
  • 14