'How to install and use just Clang-Format on Fedora 27?

I'm trying to figure out how to install the stand alone Clang-Format tool.

I've downloaded the pre build binaries for Clang from the official download page for my OS (Fedora 27).

However I failed to figure out how to run the tool.

The documentation above says clang-format is located in clang/tools/clang-format however such path doesn't exists in the downloaded files.

I searched the entire downloaded directory for 'format' and found 'clang-format' executable in the /bin/ directory.

However when I try to run it from the terminal like so: ./clang-format

The terminal says: bash: ./clang-format: No such file or directory

(I've changed the file permissions to allow execution)

I've also looked into building clang-format from source, but I failed to find instructions how to build clang-format alone without any other clang additions.

Help would be greatly appreciated. Thank you!



Solution 1:[1]

Install clang-tools extra:

sudo dnf install clang-tools-extra

For Fedora < 32, you just need to install clang, which already bundles the clang-format tool.

sudo dnf install clang

And if you want to find the location of clang-format.You can use locate.

locate clang-format

Solution 2:[2]

Fed34, this is borked. I have installed clang llvm clang-format

If I try to run it on a file it has a dump:

 #0 0x00007f3309b543f6 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/lib64/libLLVM-12.so+0xc063f6)
 #1 0x00007f3309b522e4 llvm::sys::RunSignalHandlers() (/lib64/libLLVM-12.so+0xc042e4)
 #2 0x00007f3309b52466 (/lib64/libLLVM-12.so+0xc04466)
 #3 0x00007f3308b9d320 __restore_rt (/lib64/libc.so.6+0x3d320)
 #4 0x00007f330f3fbdb4 clang::DiagnosticIDs::ProcessDiag(clang::DiagnosticsEngine&) const (/lib64/libclang-cpp.so.12+0x8e5db4)
 #5 0x00007f330f3f44bb clang::DiagnosticsEngine::EmitCurrentDiagnostic(bool) (/lib64/libclang-cpp.so.12+0x8de4bb)
 #6 0x00007f331078436c clang::Rewriter::overwriteChangedFiles() (/lib64/libclang-cpp.so.12+0x1c6e36c)
 #7 0x00005634ae4d6e1e (/usr/bin/clang-format+0xee1e)
 #8 0x00005634ae4cfed8 (/usr/bin/clang-format+0x7ed8)
 #9 0x00007f3308b87b75 __libc_start_main (/lib64/libc.so.6+0x27b75)
#10 0x00005634ae4d019e (/usr/bin/clang-format+0x819e)
Segmentation fault (core dumped)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 ljrk
Solution 2 stacker