M
M
Mars362021-03-17 19:03:19
CMake
Mars36, 2021-03-17 19:03:19

How to fix dependency(ExternalProject) build error in cmake?

I'm trying to add auto assembly of the googlebenchmark dependency using ExternalProject_add, everything seems to start successfully, but at the end it throws an error that I don't understand

[ 95%] Built target internal_threading_test
[ 97%] Built target benchmark_gtest
[100%] Built target commandlineflags_gtest
[ 33%] No install step for 'googlebenchmark'
[ 40%] Completed 'googlebenchmark'
[ 53%] Built target googlebenchmark
[ 60%] Linking CXX executable benchmark
/usr/bin/ld: googlebenchmark-build/src/libbenchmark.a(benchmark_runner.cc.o): в функции «std::thread::thread<void (*)(benchmark::internal::BenchmarkInstance const*, unsigned long, int, benchmark::internal::ThreadManager*), benchmark::internal::BenchmarkInstance const*, unsigned long&, int, benchmark::internal::ThreadManager*, void>(void (*&&)(benchmark::internal::BenchmarkInstance const*, unsigned long, int, benchmark::internal::ThreadManager*), benchmark::internal::BenchmarkInstance const*&&, unsigned long&, int&&, benchmark::internal::ThreadManager*&&)»:
benchmark_runner.cc:(.text._ZNSt6threadC2IPFvPKN9benchmark8internal17BenchmarkInstanceEmiPNS2_13ThreadManagerEEJS5_RmiS7_EvEEOT_DpOT0_[_ZNSt6threadC5IPFvPKN9benchmark8internal17BenchmarkInstanceEmiPNS2_13ThreadManagerEEJS5_RmiS7_EvEEOT_DpOT0_]+0x45): неопределённая ссылка на «pthread_create»
collect2: ошибка: выполнение ld завершилось с кодом возврата 1
make[2]: *** [CMakeFiles/benchmark.dir/build.make:179: benchmark] Ошибка 1
make[1]: *** [CMakeFiles/Makefile2:97: CMakeFiles/benchmark.dir/all] Ошибка 2
make: *** [Makefile:103: all] Ошибка 2


my
ExternalProject.cmake

include(ExternalProject)
ExternalProject_Add(googlebenchmark
  GIT_REPOSITORY    https://github.com/google/benchmark.git
  GIT_TAG           master
  SOURCE_DIR        "${CMAKE_CURRENT_BINARY_DIR}/googlebenchmark-src"
  BINARY_DIR        "${CMAKE_CURRENT_BINARY_DIR}/googlebenchmark-build"
  CONFIGURE_COMMAND ${CMAKE_COMMAND} -B ${CMAKE_CURRENT_BINARY_DIR}/googlebenchmark-build -S ${CMAKE_CURRENT_BINARY_DIR}/googlebenchmark-src -DBENCHMARK_DOWNLOAD_DEPENDENCIES=ON
  BUILD_COMMAND     ${CMAKE_COMMAND} --build ${CMAKE_CURRENT_BINARY_DIR}/googlebenchmark-build --config Release 
  INSTALL_COMMAND   ""
)

ExternalProject_Get_Property(googlebenchmark source_dir)
set(GBENCHMARK_INCLUDE_DIRS ${source_dir}/include)
set(GMOCK_INCLUDE_DIRS ${source_dir}/googlemock/include)

file(MAKE_DIRECTORY ${GBENCHMARK_INCLUDE_DIRS})
file(MAKE_DIRECTORY ${GMOCK_INCLUDE_DIRS})

ExternalProject_Get_Property(googlebenchmark binary_dir)
if(UNIX)
set(GBENCHMARK_LIBRARY_PATH ${binary_dir}/src/${CMAKE_FIND_LIBRARY_PREFIXES}benchmark.a)
else ()
set(GBENCHMARK_LIBRARY_PATH ${binary_dir}/src/${CMAKE_FIND_LIBRARY_PREFIXES}/Debug/benchmarkd.lib)
endif ()

set(GBENCHMARK_LIBRARY Benchmark)
include_directories(SOURCE_DIR/include)
add_library(${GBENCHMARK_LIBRARY} UNKNOWN IMPORTED)
set_target_properties(${GBENCHMARK_LIBRARY} PROPERTIES
    "IMPORTED_LOCATION" "${GBENCHMARK_LIBRARY_PATH}"
    "IMPORTED_LINK_INTERFACE_LIBRARIES" "${CMAKE_THREAD_LIBS_INIT}"
    "INTERFACE_INCLUDE_DIRECTORIES" "${GBENCHMARK_INCLUDE_DIRS}")
add_dependencies(${GBENCHMARK_LIBRARY} googlebenchmark)


Perhaps I forgot to add some rule? I double-checked it several times and it looks like I set the path correctly.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
klirichek, 2021-05-19
@klirichek

So it's in the docs, isn't it?
https://github.com/google/benchmark#building-with-gcc

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question