Compiler-specific flags. Compilecommands.json# 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 have come up with the idea of a compilation database. Sublime Text is much lighter than Xcode because ST is not a full featured IDE, likc Xcode. What you'll end up doing is installing/using gcc or g directly via the command line (which happens to be my preferred way of working). Command line compiling can get to be tedious though with all of the parameters that need to be passed.
This linter plugin for SublimeLinter provides an interface to gcc or other gcc-like (cross-)compiler.
Details
Installs
- Total13K
- Win6K
- Mac2K
- Linux6K
Oct 2 | Oct 1 | Sep 30 | Sep 29 | Sep 28 | Sep 27 | Sep 26 | Sep 25 | Sep 24 | Sep 23 | Sep 22 | Sep 21 | Sep 20 | Sep 19 | Sep 18 | Sep 17 | Sep 16 | Sep 15 | Sep 14 | Sep 13 | Sep 12 | Sep 11 | Sep 10 | Sep 9 | Sep 8 | Sep 7 | Sep 6 | Sep 5 | Sep 4 | Sep 3 | Sep 2 | Sep 1 | Aug 31 | Aug 30 | Aug 29 | Aug 28 | Aug 27 | Aug 26 | Aug 25 | Aug 24 | Aug 23 | Aug 22 | Aug 21 | Aug 20 | Aug 19 | Aug 18 | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Windows | 1 | 2 | 5 | 5 | 3 | 8 | 6 | 2 | 6 | 4 | 1 | 10 | 3 | 6 | 1 | 5 | 2 | 3 | 5 | 6 | 4 | 4 | 1 | 6 | 7 | 2 | 9 | 7 | 9 | 3 | 4 | 3 | 4 | 2 | 5 | 6 | 1 | 2 | 6 | 5 | 5 | 2 | 4 | 1 | 5 | 5 |
Mac | 0 | 0 | 0 | 3 | 0 | 2 | 0 | 1 | 2 | 3 | 3 | 2 | 0 | 4 | 0 | 2 | 2 | 0 | 1 | 2 | 1 | 0 | 1 | 1 | 0 | 0 | 1 | 2 | 1 | 1 | 0 | 2 | 3 | 2 | 1 | 1 | 2 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 |
Linux | 2 | 6 | 3 | 3 | 1 | 2 | 2 | 1 | 1 | 4 | 3 | 4 | 2 | 2 | 1 | 6 | 1 | 5 | 6 | 5 | 4 | 5 | 5 | 4 | 2 | 8 | 3 | 3 | 0 | 2 | 3 | 1 | 3 | 7 | 2 | 2 | 4 | 2 | 1 | 4 | 2 | 2 | 3 | 3 | 1 | 2 |
Readme
- Source
- raw.githubusercontent.com
This linter plugin for SublimeLinterprovides an interface to gcc or other gcc-like (cross-)compiler.It will be used with files that have the C/C++ syntax.If you are using clang, you may want to checkSublimeLinter-clang.
Installation
SublimeLinter must be installed in order to use this plugin.If SublimeLinter is not installed, please follow the instructionshere.
Linter installation
Before using this plugin, you must ensure that gcc
or other gcc-like compiler is installed on your system.
You may install gcc
with the following method:
- Mac OS X: OSX GCC Installer
- Linux:
gcc
could be installed by using most package managers. - Windows: MinGW-w64
Once gcc
is installed, you must ensure it is in your system PATH so that SublimeLinter can find it.This may not be as straightforward as you think, so please read Debugging PATH problems in the documentation.
Plugin installation
Please use Package Control to install the linter plugin.This will ensure that the plugin will be updated when new versions are available.If you want to install from source so you can modify the source code,you probably know what you are doing so we won't cover that here.
To install via Package Control, do the following:
Within Sublime Text, bring up the
Command Palette
by Ctrl + Shift + P and typeinstall
.Among the commands you should seePackage Control: Install Package
.If that command is not highlighted, use the keyboard or mouse to select it.There will be a pause of a few seconds while Package Control fetches the list of available plugins.When the plugin list appears, type
gcc
. Among the entries you should seeSublimeLinter-gcc
.If that entry is not highlighted, use the keyboard or mouse to select it.
Settings
Here are some most frequently used custom settings.
Setting | Description |
---|---|
executable | The compiler's binary path. This is ['gcc'] or ['g++'] by default. If you are not using them, you have to set this to your compiler binary such as ['arm-none-eabi-gcc'] . |
I | A list of directories to be added to the header's searching paths. I.e., paths for -I flags. |
args | A list of extra flags to be passed to the compiler. These should be used carefully as they may cause linting to fail. |
Here is an example settings:
Here are some useful docs for SublimeLinter settings.
- General information on how SublimeLinter works with settings.
- Variables that can be used in settings.
- Information on generic linter settings.
Notes
Hereis the official list of warning options in gcc 10.2.0. I prefer turn on all warningsvia
-Wall
(this is default for this plugin) and then suppress unwanted warnings via-Wno-
prefix.Use the
-fsyntax-only
flag inargs
gives a much faster syntax-only checking butsome warningswhich are emitted in the code optimization phase would not be caught.
Demo
Troubleshooting
C/C++ linting is not always straightforward.A few things to try when there's (almost) no linting information available:
- Try to compile from the command line, and verify it works.
- The linter might be missing some header files. They can be added with settings
I
. - Sometimes gcc fails to locate the C/C++ standard library headers.
Assuming the compilation works when executed via command line, try to compile with g++ -v
.This will display all of the hidden flags that gcc uses.As a last resort, they can all be added in settings args
.
Contributing
If you would like to contribute enhancements or fixes, please do the following:
- Fork the plugin repository.
- Hack on a separate topic branch created from the latest
master
. - Commit and push the topic branch.
- Make sure your modification could pass unittests.
- Make a pull request.
- Be patient.
Please note that modifications should follow these coding guidelines:
- Indent is 4 spaces.
- Code should pass flake8 and pep257 linters.
- Probably format codes with black code formatter.
- Vertical whitespace helps readability, don’t be afraid to use it.
- Please use descriptive variable names, no abbreviations unless they are very well known.
Thank you for helping out!
There are many things that I find missing in default C++ build in Mac Sublime Text(clang) like no bits/stdc++.h header, regular warnings on using auto keyword, using inline comparator functions etc. So I tried searching how to use brew's g++ as default build in Sublime Text without breaking anything but couldn't find anything.
First of all install brew from brew.sh.
After that install gcc using the command in terminal 'brew install gcc'.
Check if install is complete using command 'gcc-11 --version' (I got gcc-11 installed, in future you may use gcc-12,gcc-13 etc).
Now type the command 'which g++-11' to get the location where g++-11 got installed. Copy this location ( Mine was something like — /opt/homebrew/bin/g++-11 ).
Open sublime text and install 'PackageResourceViewer' from Package Control. After that open command palette and open 'PackageResourceViewer: Open resource'.
Then go to C++.
Then go to C++ Single file.
Finally replace all g++ with the location we copied earlier (/opt/homebrew/bin/g++-11).
Sublime Text C
Save this file using cmd+s and restart sublime text. Compile and build as you would usually do in sublime text (cmd+b/cmd+shift+b) and this time it would build using brew's g++.
Sublime Text C++ Compiler Macro
If you would like to revert back to original g++, just go back to C++ Single file build and change '/opt/homebrew/bin/g++-11' to 'g++' wherever applicable.
C++ Compiler For Sublime Text
Thanks