Compiler-specific flags. Like any language server, clangd works on a per-file (or per-buffer) basis. But unlike most other language servers, it must also be aware of the exact compile flags that you pass to your compiler. For this reason, people. You create a script in linux to compile and execute the source code in the Terminal and you store it in your Documents folder named as runC.sh. #!/bin/bash gnome-terminal -e '/bin/bash -c 'gcc -Wall $1 -o $2;./$2; echo; read -p 'Pressentertoscape.' ; exit; exec /bin/bash'; &'. Through a Sublime Text Build System, you call this script. How to use this tool? Just download the FastOlympicCoding folder from github and put it in you sublime package folder, here's my location:C: Users zzy81 AppData Roaming Sublime Text 3 Packages FastOlympicCoding, and there might be a user folder in the package folder too, it's the config folder for your sublime. Run C in Sublime Text 3 on Mac OSX. I know there is a built in C compiler and run plugin for ST3. This builds my program just fine. Running the code, it runs the first part in its console, but stops at the first cin. The code runs fine when I run the file compiled in ST3 straight from the terminal.
When we are participating in a programming contest, our aim is to be as quick and as efficient as possible. However, often the tools we use during contests are clunky, non-intuitive and impede our speed. The following post will help you set up Sublime Text in a way that leads to a good workflow - from reading the problem statement to submitting the solution.
Typescript Sublime Plugin
Setting up the Environment
1. Install MinGW Compiler
MinGW is a native Windows port of the GNU Compiler Collection (GCC). Install the latest MinGW compiler, after downloading from here.
Your path should preferably be C:MinGW
. Finally, add the bin
directory, C:MinGWbin
to the System PATH.
2. Install Sublime Text
Sublime Text is one of the most popular editors for development in general. It’s smooth and fast compared to other editors (being written in C++ helps that speed). Sublime also has tons of plugins you can find through Package Control. Download and install Sublime Text 3 from here.
3. Create a build system
Sublime Text provides build systems to allow users to run external programs. Create a new build system for Sublime Text for setting up C++ compilation.
Go to Tools > Build System > New Build System
. Paste the following code in the file and save it.
This can be used for piping input from the inputf.in
file, and output to the outputf.in
file. Note that this uses the -std=c++17
flag to enable the latest features of C++17. If you don't want this or want to use C++14, replace this with the -std=c++14
flag.
4. Setup window layout
Create three new files, file.cpp
, inputf.in
, and outputf.in
. Select View > Layout > Columns : 3
. This will create three columns in the workspace. Move the three files into the three columns. Select View > Groups > Max Columns : 2
.
The windows will look like above when you are done. Write a hello world program, and test its working. Use Ctrl+B
to build and execute the file.
5. Precompile headers
Now we can speed up compilation time by precompiling all the header files as mentioned here, i.e. by precompiling the bits/stdc++.h
header file. This can speed up compilation time by up to a factor of 12.
For this, first, navigate to the stdc++.h
file. This will be located at a directory similar to C:MinGWlibgccmingw326.3.0includec++mingw32bits
. Right click while pressing Shift to open a Powershell/cmd window there. Run the command g++ -std=c++17 stdc++.h
, to compile the header. Take care to use the same flags you used in your build system. Check to make sure that the stdc++.h.gch
file was created in the directory.
Finally, we can take advantage of the features of Sublime Text, namely snippets and completions.

Sublime Text features
Snippets
Snippets are smart templates that will insert text for you and adapt it to their context. Read up on the documentation of snippets at the official guide. You can create snippets like the following to quickly insert snippets of code into your file.

Sublime Text C++ Compiler
You can also create starter templates like these :
Completions
Sublime Text suggests completions that aggregate code or content while writing by catching everything that you have written, like variable names. Read up on the documentation of completions at the official guide. You can create completions like the following to quickly enter common phrases into your file.
This provides an experience close to code completion, with the advantage that you can customize it to phrases you frequently type.
You can create snippet or completion files by putting the corresponding code in a .sublime-snippet
or .sublime-completions
file.
So that's the basics out of the way, you can now begin coding. You can also explore various other features present in Sublime text, especially its plugin functionality and the most common plugins. You can also install themes to change the look and feel of the windows. There are other features that you may want to use so I’ve provided some further reading.
The below was written for clangd, but much applies to cquery and ccls as well.
CCLS#
Build and install from source or download for your distribution.See the ccls wiki for more details. How to install sapd fr v2 5 6.
Clangd#
To use clangd on Debian/Ubuntu, add the apt repositories described here.After that, install with e.g. apt install clang-tools-9
. The clangd executablewill have a version number suffix. For instance, clangd-9. You will thus have toadjust your 'clients'
dictionary in your user preferences.
To use clangd on Mac, use Homebrew: brew install llvm
. The clangd executablewill be present in /usr/local/Cellar/llvm/version/binYou probably need to install the Xcode developer command-line tools. Run the following in a terminal:
wchar_t.h
:To use clangd on Windows, install LLVM with the LLVM installer,and then add C:Program FilesLLVMbin to your %PATH%.
Compilation database#

For any project of non-trivial size, you probably have a build system in placeto compile your source files. The compilation command passed to your compilermight include things like:
- Include directories,
- Define directives,
- Compiler-specific flags.
compile_commands.json#
Like any language server, clangd works on a per-file (or per-buffer) basis. Butunlike most other language servers, it must also be aware of the exact compileflags that you pass to your compiler. For this reason, people have come up withthe idea of a compilation database.At this time, this is just a simple JSON file that describes for eachtranslation unit (i.e. a .cpp
, .c
, .m
or .mm
file) the exactcompilation flags that you pass to your compiler.
It's pretty much standardized that this file should be calledcompile_commands.json
. clangd searches for this file up in parentdirectories from the currently active document. If you don't have such a filepresent, most likely clangd will spit out nonsense errors and diagnostics aboutyour code.
As it turns out, CMake can generate this file for you if you pass it thecache variable -DCMAKE_EXPORT_COMPILE_COMMANDS=ON
when invoking CMake. It willbe present in your build directory, and you can copy that file to the root ofyour project. Make sure to ignore this file in your version control system.
If you are using a make-based build system, you could use compiledbto generate a compile_commands.json
.
Since header files are (usually) not passed to a compiler, they don't havecompile commands. Cricket bet management software. So even with a compilation database in place, clangd willstill spit out nonsense in header files. You can try to remedy this byenhancing your compilation database with your header files using this project called compdb.
To generate headers with compdb, read this closed issue.
You can also read about attempts to address this on the CMake issue tracker, along with the problemof treating header files as translation units.
Sublime Text
compile_flags.txt#
Another way to let your language server know what the include dirs are is by hand-writing a compile_flags.txt file inyour source root. Each line is one flag. This can be useful for projects that e.g. only have a Visual Studio solutionfile. For more information, see these instructions. Creating this file by hand is a reasonable place to start if your project is quitesimple.