rnburn / zipkin-cpp-opentracing

OpenTracing Tracer implementation for Zipkin in C++
Apache License 2.0
51 stars 45 forks source link

Error during compilation #6

Closed aledbf closed 7 years ago

aledbf commented 7 years ago
-- The C compiler identification is GNU 5.4.0
-- The CXX compiler identification is GNU 5.4.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found CURL: /usr/lib/x86_64-linux-gnu/libcurl.so (found version "7.47.0") 
-- Configuring done
-- Generating done
-- Build files have been written to: /tmp/build/zipkin-cpp-opentracing-bba123a37147a2da6ce861cfd7984ad53d794739/.build
Scanning dependencies of target zipkin
[  5%] Building CXX object zipkin/CMakeFiles/zipkin.dir/src/zipkin_core_types.cc.o
[ 10%] Building CXX object zipkin/CMakeFiles/zipkin.dir/src/utility.cc.o
[ 15%] Building CXX object zipkin/CMakeFiles/zipkin.dir/src/hex.cc.o
[ 20%] Building CXX object zipkin/CMakeFiles/zipkin.dir/src/tracer.cc.o
[ 25%] Building CXX object zipkin/CMakeFiles/zipkin.dir/src/ip_address.cc.o
[ 30%] Building CXX object zipkin/CMakeFiles/zipkin.dir/src/span_buffer.cc.o
[ 35%] Building CXX object zipkin/CMakeFiles/zipkin.dir/src/span_context.cc.o
[ 40%] Building CXX object zipkin/CMakeFiles/zipkin.dir/src/zipkin_reporter_impl.cc.o
[ 45%] Building CXX object zipkin/CMakeFiles/zipkin.dir/src/zipkin_http_transporter.cc.o
[ 50%] Linking CXX static library libzipkin.a
[ 50%] Built target zipkin
Scanning dependencies of target hex_test
[ 55%] Building CXX object zipkin/test/CMakeFiles/hex_test.dir/hex_test.cc.o
[ 60%] Linking CXX executable hex_test
[ 60%] Built target hex_test
Scanning dependencies of target zipkin_opentracing
[ 65%] Building CXX object zipkin_opentracing/CMakeFiles/zipkin_opentracing.dir/src/utility.cc.o
[ 70%] Building CXX object zipkin_opentracing/CMakeFiles/zipkin_opentracing.dir/src/propagation.cc.o
[ 75%] Building CXX object zipkin_opentracing/CMakeFiles/zipkin_opentracing.dir/src/opentracing.cc.o
[ 80%] Linking CXX static library libzipkin_opentracing.a
[ 80%] Built target zipkin_opentracing
Scanning dependencies of target ot_tracer_test
[ 85%] Building CXX object zipkin_opentracing/test/CMakeFiles/ot_tracer_test.dir/ot_tracer_test.cc.o
[ 90%] Linking CXX executable ot_tracer_test
/usr/bin/ld: ../../zipkin/libzipkin.a(zipkin_reporter_impl.cc.o): undefined reference to symbol 'pthread_create@@GLIBC_2.2.5'
//lib/x86_64-linux-gnu/libpthread.so.0: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
make[2]: *** [zipkin_opentracing/test/ot_tracer_test] Error 1
zipkin_opentracing/test/CMakeFiles/ot_tracer_test.dir/build.make:101: recipe for target 'zipkin_opentracing/test/ot_tracer_test' failed
CMakeFiles/Makefile2:258: recipe for target 'zipkin_opentracing/test/CMakeFiles/ot_tracer_test.dir/all' failed
make[1]: *** [zipkin_opentracing/test/CMakeFiles/ot_tracer_test.dir/all] Error 2
make: *** [all] Error 2
Makefile:138: recipe for target 'all' failed
The command '/bin/sh -c /tmp/build.sh' returned a non-zero code: 2
Makefile:61: recipe for target '.container-amd64' failed
make[1]: *** [.container-amd64] Error 2
make[1]: Leaving directory '/home/aledbf/go/src/k8s.io/ingress/images/nginx-slim'
Makefile:49: recipe for target 'sub-container-amd64' failed
make: *** [sub-container-amd64] Error 2

Any idea what could be the issue? Thanks

rnburn commented 7 years ago

It looks like it might be missing the pthreads library. Could you try replacing this file with

set(CMAKE_THREAD_PREFER_PTHREAD TRUE)
set(THREADS_PREFER_PTHREAD_FLAG TRUE)
find_package(Threads REQUIRED)

macro(_zipkin_ot_test TEST_NAME)
  add_executable(${TEST_NAME} ${ARGN})
  target_link_libraries(${TEST_NAME} Threads::Threads)
  target_link_libraries(${TEST_NAME} ${CURL_LIBRARIES} 
                                     ${OPENTRACING_LIB} 
                                     zipkin
                                     zipkin_opentracing)
  add_test(${TEST_NAME} ${TEST_NAME})
endmacro()

_zipkin_ot_test(ot_tracer_test ot_tracer_test.cc)

(I might need to add it for some other targets as well, but just want to see if that fixes it for the ot_tracer_test target)

aledbf commented 7 years ago

@rnburn here

-- The C compiler identification is GNU 5.4.0
-- The CXX compiler identification is GNU 5.4.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found CURL: /usr/lib/x86_64-linux-gnu/libcurl.so (found version "7.47.0") 
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Looking for pthread_create
-- Looking for pthread_create - not found
-- Check if compiler accepts -pthread
-- Check if compiler accepts -pthread - yes
-- Found Threads: TRUE  
CMake Error at zipkin_opentracing/test/CMakeLists.txt:2 (add_executable):
  add_executable cannot create target "ot_tracer_test" because another target
  with the same name already exists.  The existing target is an executable
  created in source directory
  "/tmp/build/zipkin-cpp-opentracing-bba123a37147a2da6ce861cfd7984ad53d794739/zipkin/test".
  See documentation for policy CMP0002 for more details.
Call Stack (most recent call first):
  zipkin_opentracing/test/CMakeLists.txt:10 (_zipkin_ot_test)

-- Configuring incomplete, errors occurred!
See also "/tmp/build/zipkin-cpp-opentracing-bba123a37147a2da6ce861cfd7984ad53d794739/.build/CMakeFiles/CMakeOutput.log".
See also "/tmp/build/zipkin-cpp-opentracing-bba123a37147a2da6ce861cfd7984ad53d794739/.build/CMakeFiles/CMakeError.log".
The command '/bin/sh -c /tmp/build.sh' returned a non-zero code: 1
Makefile:61: recipe for target '.container-amd64' failed
make[1]: *** [.container-amd64] Error 1
make[1]: Leaving directory '/home/aledbf/go/src/k8s.io/ingress/images/nginx-slim'
Makefile:49: recipe for target 'sub-container-amd64' failed
make: *** [sub-container-amd64] Error 2
rnburn commented 7 years ago

I was able to reproduce it running on ubuntu. I put in a PR that should fix it. Could you check to see if it works for you? Thanks.

aledbf commented 7 years ago

@rnburn it works now but when I try to compile nginx I get

/usr/bin/ld: //usr/local/lib/libzipkin_opentracing.a(opentracing.cc.o): relocation R_X86_64_32 against `_ZTIN6zipkin13OtSpanContextE' can not be used when making a shared object; recompile with -fPIC
//usr/local/lib/libzipkin_opentracing.a: error adding symbols: Bad value
collect2: error: ld returned 1 exit status
rnburn commented 7 years ago

Could you try rebuilding the zipkin-opentracing-cpp library, but use

cmake -DBUILD_SHARED_LIBS=1 ..

that will have it make a shared library instead of a static one.

aledbf commented 7 years ago

cmake -DBUILD_SHARED_LIBS=1 ..

Solves the issue. @rnburn thanks!