ccls cannot be built on suse linux

hi I tried to install ccls for c-c++ layer. I am not sure if the version did not support c++17?

Cmake (version 3.9.0) 
GCC (7.5.0)
clang+llvm_9

But when I run command

cmake -H. -BRelease -DCMAKE_BUILD_TYPE=Release -DCMAKE_PREFIX_PATH=/home/xxx/clang+llvm_9

fatal: No names found, cannot describe anything. – Configuring done CMake Error in CMakeLists.txt: Target “ccls” requires the language dialect “CXX17” , but CMake does not know the compile flags to use to enable it.

– Generating done CMake Generate step failed. Build files cannot be regenerated correctly.

需要加个参数才行,cmake_cxx_compile_flags=-std=c++17

CMakeLIsts.txt 里面有 setProperty (… CXX_STANDARD 17)

ccmake看下是不是缺了啥

Make sure your cmake supports CXX17 c++ - Target requires the language dialect "CXX17" (with compiler extensions), but CMake does not know the compile flags to use to enable it - Stack Overflow

You can probably work around this by deleting ... CXX_STANDARD 17 and adding -DCMAKE_CXX_FLAGS=-std=c++17

openSuse provides openSUSE Software

Hi

After I followed your hint like

cmake -H. -BRelease -DCMAKE_BUILD_TYPE=Release -DCMAKE_PREFIX_PATH=/home/ezhonke/software/clang+llvm_9 -DCMAKE_CXX_FLAGS=-std=c++17

But it seems that cmake don’t know the flag either.

Scanning dependencies of target ccls

[ 2%] Building CXX object CMakeFiles/ccls.dir/third_party/siphash.cc.o

c++: error: unrecognized command line option ‘-std=c++17’

CMakeFiles/ccls.dir/build.make:62: recipe for target ‘CMakeFiles/ccls.dir/third_party/siphash.cc.o’ failed

gmake[2]: *** [CMakeFiles/ccls.dir/third_party/siphash.cc.o] Error 1

CMakeFiles/Makefile2:67: recipe for target ‘CMakeFiles/ccls.dir/all’ failed

gmake[1]: *** [CMakeFiles/ccls.dir/all] Error 2

Makefile:129: recipe for target ‘all’ failed

gmake: *** [all] Error 2

The compiler does not support -std=c++17. See the first paragraph on Build · MaskRay/ccls Wiki · GitHub . clang>=5 or gcc>=7.2

Install a newer compiler and use CMAKE_CXX_COMPILER. There should be plenty of examples.

hi, I tried the compilation again on SUSE linux. Because I used ccls in my own ubuntu very smoothly and like it very much. with command like below:

export LD_LIBRARY_PATH=/home/xxx/git/clang+llvm-9.0.0-x86_64-linux-sles11.3/lib:/home/ezhonke/software/GCC_75/lib:$LD_LIBRARY_PATH

export PATH=/home/xxx/git/clang+llvm-9.0.0-x86_64-linux-sles11.3/bin:/home/ezhonke/software/GCC_75/bin:$PATH

/home/xxx/software/cmake-3.16.4-Linux-x86_64/bin/cmake -H. -BRelease -DCMAKE_BUILD_TYPE=Release -DCMAKE_PREFIX_PATH=/home/ezhonke/git/clang+llvm-9.0.0-x86_64-linux-sles11.3

– The CXX compiler identification is GNU 7.5.0

– Check for working CXX compiler: /home/ezhonke/software/GCC_75/bin/c++

– Check for working CXX compiler: /home/ezhonke/software/GCC_75/bin/c++ – works

– Detecting CXX compiler ABI info

– Detecting CXX compiler ABI info - done

– Detecting CXX compile features

– Detecting CXX compile features - done

– Looking for C++ include pthread.h

– Looking for C++ include pthread.h - found

– Performing Test CMAKE_HAVE_LIBC_PTHREAD

Performing Test CMAKE_HAVE_LIBC_PTHREAD - Failed

– Check if compiler accepts -pthread

– Check if compiler accepts -pthread - yes

– Found Threads: TRUE

fatal: No names found, cannot describe anything.

– Configuring done

– Generating done

– Build files have been written to: /home/xxx/git/ccls/Release

cmake --build Release

Now it can compile, but link failure:

[  2%] Linking CXX executable ccls
/usr/bin/ld: CMakeFiles/ccls.dir/src/indexer.cc.o: in function `ccls::(anonymous namespace)::IndexDataConsumer::getUsr(clang::Decl const*, ccls::(anonymous namespace)::IndexParam::DeclInfo**) const':
indexer.cc:(.text+0x3282): undefined reference to `clang::DeclarationName::getAsString[abi:cxx11]() const'
/usr/bin/ld: CMakeFiles/ccls.dir/src/indexer.cc.o: in function `ccls::(anonymous namespace)::IndexFrontendAction::CreateASTConsumer(clang::CompilerInstance&, llvm::StringRef)':
indexer.cc:(.text+0x3daa): undefined reference to `clang::MultiplexConsumer::MultiplexConsumer(std::vector<std::unique_ptr<clang::ASTConsumer, std::default_delete<clang::ASTConsumer> >, std::allocator<std::unique_ptr<clang::ASTConsumer, std::default_delete<clang::ASTConsumer> > > >)'
/usr/bin/ld: CMakeFiles/ccls.dir/src/indexer.cc.o: in function `ccls::(anonymous namespace)::IndexPPCallbacks::MacroDefined(clang::Token const&, clang::MacroDirective const*)':
indexer.cc:(.text+0x51a0): undefined reference to `llvm::Twine::str[abi:cxx11]() const'
/usr/bin/ld: indexer.cc:(.text+0x5207): undefined reference to `llvm::Twine::str[abi:cxx11]() const'
/usr/bin/ld: CMakeFiles/ccls.dir/src/indexer.cc.o: in function `ccls::(anonymous namespace)::IndexDataConsumer::handleDeclOccurence(clang::Decl const*, unsigned int, llvm::ArrayRef<clang::index::SymbolRelation>, clang::SourceLocation, clang::index::IndexDataConsumer::ASTNodeInfo)':
indexer.cc:(.text+0x6b91): undefined reference to `llvm::Twine::str[abi:cxx11]() const'
/usr/bin/ld: indexer.cc:(.text+0x86a7): undefined reference to `llvm::Twine::str[abi:cxx11]() const'
/usr/bin/ld: indexer.cc:(.text+0x8ae5): undefined reference to `llvm::Twine::str[abi:cxx11]() const'

Do I need to set some env_variables? It seems that lots of clang source missing.

有一种编译过链接不过的可能,就是(编译所用的编译器版本)和(链接使用的库编译时所用的编译器版本)不兼容。这一般会发生在g++版本和C++每代标准发布的时间接近的情况下。

可以先验证一下是不是这个问题。

Edit:

nm /path/to/wherever/is/index.cc.o | grep getAsString

vs.

nm /path/to/clang/lib/some/possible/libsth.a | grep getAsString

看看结果中对应的一长串可能叫 ZNxxxxclangxxxxxDeclarationNamexxxxgetAsStringxxxxxxx 这种怪名字是否完全一致。如果不一致,那很可能是我说的原因

Thaks for your help. But I cannot find the file you mentioned “libsth.a” I followed the guide adn downloaded prebuild clan-llvm 9.0

clang+llvm-9.0.0-x86_64-linux-sles11.3 That I cannot find the lib.

Where it should be? I use the command below in floder : clang+llvm-9.0.0-x86_64-linux-sles11.3/lib

find . -name *.a | grep -i getAsString

but found I nothing

lol. libsth.a is just a futile attempt since I have no idea where it would be.

Try

find -name *.a | xargs -n 1 nm | grep -i getAsString

You need command nm to inspect reference symbols.

HTH!

thanks for your quick resonse

I tried the command you mentioned

  1. My compiled “index.cc.o”

U _ZNK5clang15DeclarationName11getAsStringB5cxx11Ev

  1. grep from clang lib

U _ZNK5clang15DeclarationName11getAsStringEv

It seems a little bit difference

is it the root cause? How can I fix it?

My suspicion confirmed. Exactly the root cause.

U r using g++ 7.5.0, which according to gcc roadmap, originates from gcc 7 branch, around early 2017. Like I said, coincide with the official release of c++17 standard. Same reason why gcc4.9 and gcc5.4 can’t coexist (around c++14 No doesn’t look right. I’m not sure what I’m talking about. For more info, check out this SO answer).

The root cause is that g++ 7.5 mangles differently from g++ 9, which built your libclang-llvm. To successfully link, you would need to either use libclang built from 7.5 or use g++ 9 to build ccls.

Also note the version of libstdc++ also need to be compatible with the choice of g++ version.

If getting environment fixed is too much pain in the S on SUSE(especially the libstdc++ part), the easiest path is to freshly build libclang/llvm and ccls with libc++ using one same compiler.

Edit: Another look. I might be wrong about your libclang compiler version. Forget what I said about g++ 9. Try determining which version of gcc built your libclang.

YAEdit:

On a second look, this line seems a bit peculiar. Is this your only nm output from libclang?

Actually, there are a lot of differernt items.

1 0000000000000000 T _ZNK4llvm12VersionTuple11getAsStringEv 2 0000000000000000 T _ZNK4llvm10CondOpInit11getAsStringEv 3 0000000000000000 T _ZNK4llvm10FoldOpInit11getAsStringEv 4 0000000000000000 W _ZNK4llvm10StringInit11getAsStringEv 5 0000000000000000 T _ZNK4llvm10TernOpInit11getAsStringEv 6 0000000000000000 T _ZNK4llvm10VarBitInit11getAsStringEv 7 0000000000000000 T _ZNK4llvm10VarDefInit11getAsStringEv 8 0000000000000000 T _ZNK4llvm11RecordRecTy11getAsStringEv 9 0000000000000000 T _ZNK4llvm11StringRecTy11getAsStringEv 10 0000000000000000 T _ZNK4llvm18VarListElementInit11getAsStringEv 11 0000000000000000 W _ZNK4llvm7BitInit11getAsStringEv 12 0000000000000000 T _ZNK4llvm7DagInit11getAsStringEv 13 0000000000000000 T _ZNK4llvm7DefInit11getAsStringEv 14 0000000000000000 T _ZNK4llvm7IntInit11getAsStringEv 15 0000000000000000 W _ZNK4llvm7VarInit11getAsStringEv 16 0000000000000000 W _ZNK4llvm8BitRecTy11getAsStringEv 17 0000000000000000 T _ZNK4llvm8BitsInit11getAsStringEv 18 0000000000000000 W _ZNK4llvm8CodeInit11getAsStringEv 19 0000000000000000 T _ZNK4llvm8DagRecTy11getAsStringEv 20 0000000000000000 W _ZNK4llvm8IntRecTy11getAsStringEv 21 0000000000000000 T _ZNK4llvm8ListInit11getAsStringEv 22 0000000000000000 T _ZNK4llvm8UnOpInit11getAsStringEv 23 0000000000000000 T _ZNK4llvm9BinOpInit11getAsStringEv 24 0000000000000000 T _ZNK4llvm9BitsRecTy11getAsStringEv 25 0000000000000000 W _ZNK4llvm9CodeRecTy11getAsStringEv 26 0000000000000000 W _ZNK4llvm9FieldInit11getAsStringEv 27 0000000000000000 T _ZNK4llvm9IsAOpInit11getAsStringEv 28 0000000000000000 T _ZNK4llvm9ListRecTy11getAsStringEv 29 0000000000000000 W _ZNK4llvm9UnsetInit11getAsStringEv 30 U _ZNK4llvm7DagInit11getAsStringEv 31 U _ZNK4llvm12AttributeSet11getAsStringEb 32 U _ZNK4llvm13AttributeList11getAsStringEjb 33 U _ZNK4llvm9Attribute11getAsStringEb 34 0000000000000000 T _ZNK4llvm12AttributeSet11getAsStringEb 35 0000000000000000 T _ZNK4llvm13AttributeList11getAsStringEjb 36 0000000000000000 T _ZNK4llvm16AttributeSetNode11getAsStringEb 37 0000000000000000 T _ZNK4llvm9Attribute11getAsStringEb 38 0000000000000000 t _ZZNK4llvm9Attribute11getAsStringEbENK3$_0clEPKc 39 0000000000000000 T LLVMGetAsString

And I tried pre-build clang 7.10, it also failed.

May be I need to compile clang-llvm by myself not dowload pre-build one.

Thanks

Yep, that’d be your best bet.