cquery
cquery copied to clipboard
Cannot build cquery on Ubuntu, undefined reference to symbol 'pthread_setname_np@@GLIBC_2.12'
master at 32005b79018cdfc50262bfdb54d24ffafa19b88d
Follow build instructions at https://github.com/cquery-project/cquery/wiki/Building-cquery
jamescook@jamescook:/w/cquery2/build (master)$ cmake --build .
...<normal build>...
[100%] Linking CXX executable cquery
/usr/bin/ld: CMakeFiles/cquery.dir/src/platform_posix.cc.o: undefined reference to symbol 'pthread_setname_np@@GLIBC_2.12'
//lib/x86_64-linux-gnu/libpthread.so.0: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
CMakeFiles/cquery.dir/build.make:2384: recipe for target 'cquery' failed
make[2]: *** [cquery] Error 1
CMakeFiles/Makefile2:99: recipe for target 'CMakeFiles/cquery.dir/all' failed
make[1]: *** [CMakeFiles/cquery.dir/all] Error 2
Makefile:129: recipe for target 'all' failed
make: *** [all] Error 2
After chatting with jacobdufault we tried changing CMakeLists.txt like this:
# Enable threading support
+set(CMAKE_THREAD_PREFER_PTHREAD ON)
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
target_link_libraries(cquery PRIVATE Threads::Threads)
Which didn't help, same error.
jamescook@jamescook:/w/cquery2 (master)$ uname -a
Linux <redacted> 4.9.0-7-amd64 #1 SMP Debian 4.9.110-1 (2018-07-05) x86_64 GNU/Linux
jamescook@jamescook:/w/cquery2 (master)$ cmake --version
cmake version 3.9.0
jamescook@jamescook:/w/cquery2 (master)$ ldd --version
ldd (Debian GLIBC 2.24-12) 2.24
@DaanDeMeyer, @bstaletic any thoughts?
https://github.com/kronihias/mcfx/issues/1 This issue seems similar and was fixed by changing the linking order although I'm not sure what we'd have to change in CMake.
I do remember @bstaletic mentioning a CMake bug where Threads did not work if C wasn't specified as a project language but if I remember correctly that was fixed in an earlier version of CMake.
Can you you compile with -DCMAKE_VERBOSE_MAKEFILE=ON
and post the output? The pthreads flag should be in there somewhere.
I don't see a pthread flag below.
jamescook@jamescook:/w/cquery2/build (master)$ cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=release -DCMAKE_EXPORT_COMPILE_COMMANDS=YES -DCMAKE_VERBOSE_MAKEFILE=ON -- Using downloaded Clang -- Clang already downloaded -- Configuring done -- Generating done -- Build files have been written to: /w/cquery2/build jamescook@jamescook:/w/cquery2/build (master)$ cmake --build . /usr/bin/cmake -H/w/cquery2 -B/w/cquery2/build --check-build-system CMakeFiles/Makefile.cmake 0 /usr/bin/cmake -E cmake_progress_start /w/cquery2/build/CMakeFiles /w/cquery2/build/CMakeFiles/progress.marks make -f CMakeFiles/Makefile2 all make[1]: Entering directory '/w/cquery2/build' make -f third_party/reproc/CMakeFiles/reproc.dir/build.make third_party/reproc/CMakeFiles/reproc.dir/depend make[2]: Entering directory '/w/cquery2/build' cd /w/cquery2/build && /usr/bin/cmake -E cmake_depends "Unix Makefiles" /w/cquery2 /w/cquery2/third_party/reproc /w/cquery2/build /w/cquery2/build/third_party/reproc /w/cquery2/build/third_party/reproc/CMakeFiles/reproc.dir/DependInfo.cmake --color= make[2]: Leaving directory '/w/cquery2/build' make -f third_party/reproc/CMakeFiles/reproc.dir/build.make third_party/reproc/CMakeFiles/reproc.dir/build make[2]: Entering directory '/w/cquery2/build' [ 1%] Linking CXX static library lib/libreproc.a cd /w/cquery2/build/third_party/reproc && /usr/bin/cmake -P CMakeFiles/reproc.dir/cmake_clean_target.cmake cd /w/cquery2/build/third_party/reproc && /usr/bin/cmake -E cmake_link_script CMakeFiles/reproc.dir/link.txt --verbose=1 /usr/bin/ar qc lib/libreproc.a CMakeFiles/reproc.dir/src/c/common.c.o CMakeFiles/reproc.dir/src/c/posix/fork.c.o CMakeFiles/reproc.dir/src/c/posix/pipe.c.o CMakeFiles/reproc.dir/src/c/posix/reproc.c.o CMakeFiles/reproc.dir/src/c/posix/process.c.o CMakeFiles/reproc.dir/src/cpp/reproc.cpp.o CMakeFiles/reproc.dir/src/cpp/error.cpp.o /usr/bin/ranlib lib/libreproc.a make[2]: Leaving directory '/w/cquery2/build' [ 8%] Built target reproc make -f CMakeFiles/cquery.dir/build.make CMakeFiles/cquery.dir/depend make[2]: Entering directory '/w/cquery2/build' cd /w/cquery2/build && /usr/bin/cmake -E cmake_depends "Unix Makefiles" /w/cquery2 /w/cquery2 /w/cquery2/build /w/cquery2/build /w/cquery2/build/CMakeFiles/cquery.dir/DependInfo.cmake --color= make[2]: Leaving directory '/w/cquery2/build' make -f CMakeFiles/cquery.dir/build.make CMakeFiles/cquery.dir/build make[2]: Entering directory '/w/cquery2/build' [ 9%] Linking CXX executable cquery /usr/bin/cmake -E cmake_link_script CMakeFiles/cquery.dir/link.txt --verbose=1 /usr/bin/c++ -O3 -DNDEBUG -rdynamic CMakeFiles/cquery.dir/third_party/siphash.cc.o CMakeFiles/cquery.dir/third_party/pugixml/src/pugixml.cpp.o CMakeFiles/cquery.dir/src/c_cpp_properties.cc.o CMakeFiles/cquery.dir/src/cache_manager.cc.o CMakeFiles/cquery.dir/src/clang_complete.cc.o CMakeFiles/cquery.dir/src/clang_cursor.cc.o CMakeFiles/cquery.dir/src/clang_format.cc.o CMakeFiles/cquery.dir/src/clang_index.cc.o CMakeFiles/cquery.dir/src/clang_indexer.cc.o CMakeFiles/cquery.dir/src/clang_system_include_extractor.cc.o CMakeFiles/cquery.dir/src/clang_translation_unit.cc.o CMakeFiles/cquery.dir/src/clang_utils.cc.o CMakeFiles/cquery.dir/src/code_complete_cache.cc.o CMakeFiles/cquery.dir/src/command_line.cc.o CMakeFiles/cquery.dir/src/compiler.cc.o CMakeFiles/cquery.dir/src/diagnostics_engine.cc.o CMakeFiles/cquery.dir/src/file_consumer.cc.o CMakeFiles/cquery.dir/src/file_contents.cc.o CMakeFiles/cquery.dir/src/file_types.cc.o CMakeFiles/cquery.dir/src/fuzzy_match.cc.o CMakeFiles/cquery.dir/src/iindexer.cc.o CMakeFiles/cquery.dir/src/import_manager.cc.o CMakeFiles/cquery.dir/src/import_pipeline.cc.o CMakeFiles/cquery.dir/src/include_complete.cc.o CMakeFiles/cquery.dir/src/method.cc.o CMakeFiles/cquery.dir/src/lex_utils.cc.o CMakeFiles/cquery.dir/src/lsp.cc.o CMakeFiles/cquery.dir/src/lsp_diagnostic.cc.o CMakeFiles/cquery.dir/src/match.cc.o CMakeFiles/cquery.dir/src/message_handler.cc.o CMakeFiles/cquery.dir/src/options.cc.o CMakeFiles/cquery.dir/src/platform_posix.cc.o CMakeFiles/cquery.dir/src/platform_win.cc.o CMakeFiles/cquery.dir/src/platform.cc.o CMakeFiles/cquery.dir/src/position.cc.o CMakeFiles/cquery.dir/src/project.cc.o CMakeFiles/cquery.dir/src/query_utils.cc.o CMakeFiles/cquery.dir/src/query.cc.o CMakeFiles/cquery.dir/src/queue_manager.cc.o CMakeFiles/cquery.dir/src/recorder.cc.o CMakeFiles/cquery.dir/src/semantic_highlight_symbol_cache.cc.o CMakeFiles/cquery.dir/src/serializer.cc.o CMakeFiles/cquery.dir/src/standard_includes.cc.o CMakeFiles/cquery.dir/src/task.cc.o CMakeFiles/cquery.dir/src/test.cc.o CMakeFiles/cquery.dir/src/third_party_impl.cc.o CMakeFiles/cquery.dir/src/threaded_queue.cc.o CMakeFiles/cquery.dir/src/timer.cc.o CMakeFiles/cquery.dir/src/timestamp_manager.cc.o CMakeFiles/cquery.dir/src/type_printer.cc.o CMakeFiles/cquery.dir/src/utils.cc.o CMakeFiles/cquery.dir/src/work_thread.cc.o CMakeFiles/cquery.dir/src/working_files.cc.o CMakeFiles/cquery.dir/src/messages/cquery_base.cc.o CMakeFiles/cquery.dir/src/messages/cquery_call_hierarchy.cc.o CMakeFiles/cquery.dir/src/messages/cquery_callers.cc.o CMakeFiles/cquery.dir/src/messages/cquery_did_view.cc.o CMakeFiles/cquery.dir/src/messages/cquery_file_info.cc.o CMakeFiles/cquery.dir/src/messages/cquery_freshen_index.cc.o CMakeFiles/cquery.dir/src/messages/cquery_index_file.cc.o CMakeFiles/cquery.dir/src/messages/cquery_inheritance_hierarchy.cc.o CMakeFiles/cquery.dir/src/messages/cquery_vars.cc.o CMakeFiles/cquery.dir/src/messages/cquery_wait.cc.o CMakeFiles/cquery.dir/src/messages/exit.cc.o CMakeFiles/cquery.dir/src/messages/initialize.cc.o CMakeFiles/cquery.dir/src/messages/shutdown.cc.o CMakeFiles/cquery.dir/src/messages/text_document_code_action.cc.o CMakeFiles/cquery.dir/src/messages/text_document_code_lens.cc.o CMakeFiles/cquery.dir/src/messages/text_document_completion.cc.o CMakeFiles/cquery.dir/src/messages/text_document_definition.cc.o CMakeFiles/cquery.dir/src/messages/text_document_did_change.cc.o CMakeFiles/cquery.dir/src/messages/text_document_did_close.cc.o CMakeFiles/cquery.dir/src/messages/text_document_did_open.cc.o CMakeFiles/cquery.dir/src/messages/text_document_did_save.cc.o CMakeFiles/cquery.dir/src/messages/text_document_document_highlight.cc.o CMakeFiles/cquery.dir/src/messages/text_document_document_link.cc.o CMakeFiles/cquery.dir/src/messages/text_document_document_symbol.cc.o CMakeFiles/cquery.dir/src/messages/text_document_formatting.cc.o CMakeFiles/cquery.dir/src/messages/text_document_hover.cc.o CMakeFiles/cquery.dir/src/messages/text_document_implementation.cc.o CMakeFiles/cquery.dir/src/messages/text_document_range_formatting.cc.o CMakeFiles/cquery.dir/src/messages/text_document_references.cc.o CMakeFiles/cquery.dir/src/messages/text_document_rename.cc.o CMakeFiles/cquery.dir/src/messages/text_document_signature_help.cc.o CMakeFiles/cquery.dir/src/messages/text_document_type_definition.cc.o CMakeFiles/cquery.dir/src/messages/workspace_did_change_configuration.cc.o CMakeFiles/cquery.dir/src/messages/workspace_did_change_watched_files.cc.o CMakeFiles/cquery.dir/src/messages/workspace_execute_command.cc.o CMakeFiles/cquery.dir/src/messages/workspace_symbol.cc.o -o cquery -Wl,-rpath,/w/cquery2/build/clang+llvm-6.0.1-x86_64-linux-gnu-ubuntu-14.04/lib: third_party/reproc/lib/libreproc.a clang+llvm-6.0.1-x86_64-linux-gnu-ubuntu-14.04/lib/libclang.so -ldl /usr/bin/ld: CMakeFiles/cquery.dir/src/platform_posix.cc.o: undefined reference to symbol 'pthread_setname_np@@GLIBC_2.12' //lib/x86_64-linux-gnu/libpthread.so.0: error adding symbols: DSO missing from command line collect2: error: ld returned 1 exit status CMakeFiles/cquery.dir/build.make:2387: recipe for target 'cquery' failed make[2]: *** [cquery] Error 1 make[2]: Leaving directory '/w/cquery2/build' CMakeFiles/Makefile2:102: recipe for target 'CMakeFiles/cquery.dir/all' failed make[1]: *** [CMakeFiles/cquery.dir/all] Error 2 make[1]: Leaving directory '/w/cquery2/build' Makefile:132: recipe for target 'all' failed make: *** [all] Error 2
Does it work if you add the pthread flag explicitly? (set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread")
should do the trick
Yes, explicitly adding -pthread makes it link.
I wonder what's the output of nm ./cquery | grep pthread_setname_np
.
For me that's:
U pthread_setname_np@@GLIBC_2.12
What it says is, there is no fixed memory address offset for the symbol because the symbol is U
ndefined. In other words, the symbol should be resolved at load time when the loader loads some shared object - in this case libpthread.so.
So, if all of this is correct, ldd cquery
should tell us that there is a need to link against libpthread.so
:
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007fd3438e6000)
Lastly, -pthread
should have been in the flags, but it also should have appeared in the cmake configuration step:
-- Looking for C++ include pthread.h
-- Looking for C++ include pthread.h - found
-- Looking for pthread_create
-- Looking for pthread_create - not found
-- Check if compiler accepts -pthread
-- Check if compiler accepts -pthread - yes
After building with the workaround above I get the same thing as you:
jamescook@jamescook:/w/cquery2/build (master)$ nm ./cquery | grep pthread_setname_np U pthread_setname_np@@GLIBC_2.12 jamescook@jamescook:/w/cquery2/build (master)$ ldd cquery linux-vdso.so.1 (0x00007ffef9e9a000) libclang.so.6 => /w/cquery2/build/clang+llvm-6.0.1-x86_64-linux-gnu-ubuntu-14.04/lib/libclang.so.6 (0x00007f734786c000) libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f7347668000) libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f73472e3000) libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f7346fdf000) libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f7346dc7000) libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f7346baa000) libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f734680b000) libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007f73465f1000) librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007f73463e9000) libtinfo.so.5 => /lib/x86_64-linux-gnu/libtinfo.so.5 (0x00007f73461bf000) /lib64/ld-linux-x86-64.so.2 (0x00007f734ba93000)
Alright, so what is the output of cmake configuration without the explicit -pthread
?
Sorry, which command do you want me to run?
On Wed, Aug 22, 2018 at 10:06 AM Boris Staletic [email protected] wrote:
Alright, so what is the output of cmake configuration without the explicit -pthread?
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/cquery-project/cquery/issues/782#issuecomment-415105884, or mute the thread https://github.com/notifications/unsubscribe-auth/AcGfMM5fmhicVJbRz1SwyFmOQp-eE_93ks5uTY-kgaJpZM4WGTNj .
Try changing the project call to project(cquery LANGUAGES C CXX)
@DaanDeMeyer That bug was fixed in cmake 3.4.
@jamescookmd The one before cmake --build
. Probably just cmake ..
, but in a clean build directory.
After reverting the workaround (the explicit -pthread):
jamescook@jamescook:/w/cquery2 (master)$ git stash save Saved working directory and index state WIP on master: 32005b79 Check if LOGURU_STACKTRACES is allowed jamescook@jamescook:/w/cquery2 (master)$ git status On branch master Your branch is up to date with 'origin/master'.
nothing to commit, working tree clean
jamescook@jamescook:/w/cquery2 (master)$ mkdir build2 && cd build2
jamescook@jamescook:/w/cquery2/build2 (master)$ cmake ..
-- The CXX compiler identification is GNU 7.3.0
-- 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
-- Setting build type to 'Release' as none was specified.
-- Using downloaded Clang
-- Downloading Clang 6.0.1 (https://releases.llvm.org/6.0.1/clang+llvm-6.0.1-x86_64-linux-gnu-ubuntu-14.04.tar.xz) ...
-- Extracting downloaded Clang with CMake built-in tar ...
-- The C compiler identification is GNU 7.3.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
-- Looking for pipe2
-- Looking for pipe2 - found
-- Found Clang: /w/cquery2/build2/clang+llvm-6.0.1-x86_64-linux-gnu-ubuntu-14.04/lib/libclang.so (found suitable version "6.0.1", minimum required is "6.0.0")
-- Looking for C++ include pthread.h
-- Looking for C++ include pthread.h - found
-- Looking for pthread_create
-- Looking for pthread_create - found
-- Found Threads: TRUE
-- Configuring done
-- Generating done
-- Build files have been written to: /w/cquery2/build2
From your output:
-- Looking for C++ include pthread.h
-- Looking for C++ include pthread.h - found
-- Looking for pthread_create
-- Looking for pthread_create - found
-- Found Threads: TRUE
Which is missing the crucial step that is:
-- Check if compiler accepts -pthread
-- Check if compiler accepts -pthread - yes
I wonder if you could properly configure ycmd. For the purpose of this issue, forget the ycmd installation guide. Just run cmake /path/to/ycmd/cpp
.