clang 5.0.2 not auto-adding -pthread during link?

René J.V. Bertin rjvbertin at gmail.com
Thu Jun 21 18:28:38 UTC 2018


Hi,

A strange issue I've seen only when building KDevelop to date though I think the bug is elsewhere. Build is with clang 5.0.2 installed from the llvm.org .deb packages, the active GCC is 7.3.0 (Ubuntu build)

%> (cd build/plugins/astyle ; clang++ -fPIC -Ofast -g -DNDEBUG -isystem/opt/local/include -std=c++11 -m64 -std=c++0x -fno-operator-names -fno-exceptions -DQT_NO_EXCEPTIONS -Wno-gnu-zero-variadic-macro-arguments -Wall -Wextra -Wcast-align -Wchar-subscripts -Wformat-security -Wno-long-long -Wpointer-arith -Wundef -Wnon-virtual-dtor -Woverloaded-virtual -Werror=return-type -Wvla -Wdate-time -Wl,--no-undefined -Wl,--fatal-warnings -Wl,--enable-new-dtags -Wl,-R,/opt/local/lib -Wl,-rpath,/opt/local/libexec/qt5/lib -shared -o kdevastyle.so CMakeFiles/kdevastyle.dir/astyle_plugin.cpp.o CMakeFiles/kdevastyle.dir/astyle_preferences.cpp.o CMakeFiles/kdevastyle.dir/astyle_formatter.cpp.o CMakeFiles/kdevastyle.dir/astyle_stringiterator.cpp.o CMakeFiles/kdevastyle.dir/debug.cpp.o CMakeFiles/kdevastyle.dir/kdevastyle_autogen/mocs_compilation.cpp.o -Wl,-rpath,/opt/local/lib/x86_64-linux-gnu:/opt/local/libexec/qt5/lib 3rdparty/libastyle/libastylelib.a ../../kdevplatform/util/libKDevPlatformUtil.so.5.2.3 ../../kdevplatform/interfaces/libKDevPlatformInterfaces.so.5.2.3 /opt/local/lib/x86_64-linux-gnu/libKF5TextEditor.so.5.47.0 /opt/local/lib/x86_64-linux-gnu/libKF5Parts.so.5.47.0 /opt/local/lib/x86_64-linux-gnu/libKF5KIOWidgets.so.5.47.0 /opt/local/lib/x86_64-linux-gnu/libKF5KIOCore.so.5.47.0 /opt/local/lib/x86_64-linux-gnu/libKF5JobWidgets.so.5.47.0 /opt/local/libexec/qt5/lib/libQt5Concurrent.so.5.9.6 /opt/local/lib/x86_64-linux-gnu/libKF5XmlGui.so.5.47.0 /opt/local/lib/x86_64-linux-gnu/libKF5TextWidgets.so.5.47.0 /opt/local/lib/x86_64-linux-gnu/libKF5Completion.so.5.47.0 /opt/local/lib/x86_64-linux-gnu/libKF5SonnetUi.so.5.47.0 /opt/local/libexec/qt5/lib/libQt5Network.so.5.9.6 /opt/local/lib/x86_64-linux-gnu/libKF5Service.so.5.47.0 /opt/local/lib/x86_64-linux-gnu/libKF5ItemModels.so.5.47.0 /opt/local/lib/x86_64-linux-gnu/libKF5ConfigWidgets.so.5.47.0 /opt/local/lib/x86_64-linux-gnu/libKF5WidgetsAddons.so.5.47.0 /opt/local/lib/x86_64-linux-gnu/libKF5I18n.so.5.47.0 /opt/local/lib/x86_64-linux-gnu/libKF5Codecs.so.5.47.0 /opt/local/lib/x86_64-linux-gnu/libKF5ConfigGui.so.5.47.0 /opt/local/libexec/qt5/lib/libQt5Xml.so.5.9.6 /opt/local/lib/x86_64-linux-gnu/libKF5ConfigCore.so.5.47.0 /opt/local/lib/x86_64-linux-gnu/libKF5Auth.so.5.47.0 /opt/local/libexec/qt5/lib/libQt5DBus.so.5.9.6 /opt/local/libexec/qt5/lib/libQt5Widgets.so.5.9.6 /opt/local/lib/x86_64-linux-gnu/libKF5CoreAddons.so.5.47.0 /opt/local/libexec/qt5/lib/libQt5Gui.so.5.9.6 /opt/local/libexec/qt5/lib/libQt5Core.so.5.9.6 -Wl,-rpath-link,/opt/local/lib/x86_64-linux-gnu:/opt/local/libexec/qt5/lib   )
CMakeFiles/kdevastyle.dir/astyle_formatter.cpp.o: In function `__gnu_cxx::__exchange_and_add_dispatch(int*, int)':
/usr/lib/gcc/x86_64-linux-gnu/7.3.0/../../../../include/c++/7.3.0/ext/atomicity.h:81: undefined reference to `__pthread_key_create'
/usr/lib/gcc/x86_64-linux-gnu/7.3.0/../../../../include/c++/7.3.0/ext/atomicity.h:81: undefined reference to `__pthread_key_create'
3rdparty/libastyle/libastylelib.a(ASBeautifier.cpp.o): In function `__gnu_cxx::__exchange_and_add_dispatch(int*, int)':
/usr/lib/gcc/x86_64-linux-gnu/7.3.0/../../../../include/c++/7.3.0/ext/atomicity.h:81: undefined reference to `__pthread_key_create'
/usr/lib/gcc/x86_64-linux-gnu/7.3.0/../../../../include/c++/7.3.0/ext/atomicity.h:81: undefined reference to `__pthread_key_create'
/usr/lib/gcc/x86_64-linux-gnu/7.3.0/../../../../include/c++/7.3.0/ext/atomicity.h:81: undefined reference to `__pthread_key_create'
3rdparty/libastyle/libastylelib.a(ASBeautifier.cpp.o):/usr/lib/gcc/x86_64-linux-gnu/7.3.0/../../../../include/c++/7.3.0/ext/atomicity.h:81: more undefined references to `__pthread_key_create' follow

Using g++ as the link driver solves this issue, so does adding `-pthread` to the clang++ commandline.

As far as I can tell (now) this only happens in the kdevastyle, and I've "fixed" it with a cmake tweak (below).
Has anyone seen this, or something similar? I'm guessing that clang++ doesn't normally omit the -pthread argument, so why here?

Thanks,
R.

CMake tweak:
if(UNIX AND NOT APPLE)
    if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
        target_link_libraries(kdevastyle "-pthread")
    endif()
endif()



More information about the KDevelop-devel mailing list