Skip to content

gtest pthread failures #15

@mbanck

Description

@mbanck

On Debian unstable, gtest seems to require pthreads, I get the following linking failures:

/usr/bin/ld: [ 81%] Linking CXX executable math_test
cd /<<PKGBUILDDIR>>/obj-x86_64-linux-gnu/tests/units/mathutil && /usr/bin/cmake -E cmake_link_script CMakeFiles/math_test.dir/link.txt --verbose=1
/usr/bin/c++ -g -O2 -fdebug-prefix-map=/<<PKGBUILDDIR>>=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -Wl,-z,relro CMakeFiles/math_test.dir/math.cpp.o -o math_test  ../../../src/libecpint.a /usr/lib/x86_64-linux-gnu/libgtest.a ../../../external/Faddeeva/libFaddeeva.a /usr/lib/x86_64-linux-gnu/libpugixml.so
/usr/lib/x86_64-linux-gnu/libgtest.a(gtest-all.cc.o): in function `testing::internal::ThreadLocal<std::vector<testing::internal::TraceInfo, std::allocator<testing::internal::TraceInfo> > >::~ThreadLocal()':
./obj-x86_64-linux-gnu/googletest/./googletest/include/gtest/internal/gtest-port.h:1750: undefined reference to `pthread_getspecific'

The pkg-config files for gtest mention -lpthread.

This patch makes it link, I'm not sure whether there's some better way to figure out how gtest is built/needs pthread (I guess this is a band-aid that won't work for everybody):

--- ./external/ImportGTest.cmake.orig   2020-10-13 21:19:43.403659158 +0200
+++ ./external/ImportGTest.cmake        2020-10-13 21:19:53.967714651 +0200
@@ -39,5 +39,5 @@
   message("Found googletest")
   add_library(gtest INTERFACE)
   target_include_directories(gtest INTERFACE ${GTEST_INCLUDE_DIR})
-  target_link_libraries(gtest INTERFACE ${GTEST_LIBRARY})
+  target_link_libraries(gtest INTERFACE ${GTEST_LIBRARY} pthread)
 endif()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions