ctrl+shift+p filters: :st2 :st3 :win :osx :linux
Browse

Sublime​Linter-gcc

by SublimeLinter ST3 Trending

This linter plugin for SublimeLinter provides an interface to gcc or other gcc-like (cross-)compiler.

Details

Installs

  • Total 2K
  • Win 683
  • OS X 283
  • Linux 814
Feb 25 Feb 24 Feb 23 Feb 22 Feb 21 Feb 20 Feb 19 Feb 18 Feb 17 Feb 16 Feb 15 Feb 14 Feb 13 Feb 12 Feb 11 Feb 10 Feb 9 Feb 8 Feb 7 Feb 6 Feb 5 Feb 4 Feb 3 Feb 2 Feb 1 Jan 31 Jan 30 Jan 29 Jan 28 Jan 27 Jan 26 Jan 25 Jan 24 Jan 23 Jan 22 Jan 21 Jan 20 Jan 19 Jan 18 Jan 17 Jan 16 Jan 15 Jan 14 Jan 13 Jan 12 Jan 11
Windows 2 4 5 7 7 6 5 3 4 3 2 9 8 5 4 4 4 9 9 10 3 1 2 2 4 6 1 1 8 1 3 6 2 1 4 1 4 5 3 3 2 2 3 0 1 4
OS X 0 5 4 3 2 3 5 4 1 2 3 7 1 3 2 1 3 1 2 6 2 5 1 3 0 0 0 1 1 1 1 1 1 0 0 0 0 2 1 2 0 0 1 0 1 3
Linux 2 14 12 10 8 4 5 7 9 7 3 4 7 6 7 6 6 4 10 12 8 3 5 2 8 7 4 7 5 14 18 20 21 19 17 5 1 6 6 8 3 7 2 3 4 2

Readme

Source
raw.​githubusercontent.​com

SublimeLinter-gcc

This linter plugin for SublimeLinter provides 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 should consider Sublime​Linter-clang.

Installation

SublimeLinter must be installed in order to use this plugin. If SublimeLinter is not installed, please follow the instructions here.

Linter installation

Before using this plugin, you must ensure that gcc or other gcc-like (cross-)compiler is installed on your system.

You may install gcc with the following method:

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 How linter executables are located in the documentation.

Once you have installed gcc you can proceed to install the SublimeLinter-gcc plugin if it is not yet installed.

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:

  1. Within Sublime Text, bring up the Command Palette and type install. Among the commands you should see Package 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.

  2. When the plugin list appears, type gcc. Among the entries you should see SublimeLinter-gcc. If that entry is not highlighted, use the keyboard or mouse to select it.

Settings

For general information on how SublimeLinter works with settings, please see Settings. For information on generic linter settings, please see Linter Settings.

In addition to the standard SublimeLinter settings, SublimeLinter-gcc provides its own settings.

Setting Description
executable If you are not using gcc, you have to set this to your compiler binary. (like arm-none-eabi-gcc)
include_dirs A list of directories to be added to the header search paths (-I is not needed).
extra_flags A list of extra flags to pass to the compiler. These should be used carefully, as they may cause linting to fail.
  • All settings above could be C or C++ specific. To do that, simply add c_ or c++_ prefix to a setting's key.

  • For project-specific settings, ${project_folder} can be used to specify relative path.

Here is an example settings:

"SublimeLinter":
{
    "linters":
    {
        "gcc": {
            "c_executable": "gcc",
            "c_extra_flags": [
                "-fsyntax-only",
                "-std=c90"
            ],
            "c++_executable": "g++",
            "c++_extra_flags": [
                "-fsyntax-only",
                "-std=c++11"
            ],
            "include_dirs": [
                "${project_folder}/include"
            ]
        }
    }
},

Notes

  • Here is the official list of warning options in gcc 7.3.0. I prefer turn on all warnings via -Wall (this is default for this plugin) and then suppress unwanted warnings via -Wno- prefix.

  • Flag -fsyntax-only gives a much faster syntax-only checking but some warnings which are emitted in the code optimization phase would not be caught.

Demo

linting_example

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 include_dirs.
  • 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 extra_flags.

Contributing

If you would like to contribute enhancements or fixes, please do the following:

  1. Fork the plugin repository.
  2. Hack on a separate topic branch created from the latest master.
  3. Commit and push the topic branch.
  4. Make sure your modification could pass unittests.
  5. Make a pull request.
  6. Be patient. ;-)

Please note that modifications should follow these coding guidelines:

  • Indent is 4 spaces.
  • Code should pass flake8 and pep257 linters.
  • 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!

Supporters

Thank you guys for sending me some cups of coffee.