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

Sublime​Linter-contrib-clang

by nirm03 ST3

SublimeLinter plugin for C/C++, using clang

Details

Installs

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

Readme

Source
raw.​githubusercontent.​com

SublimeLinter-clang

This linter plugin for SublimeLinter provides an interface to clang. It will be used with files that have the C/C Improved/C++ syntax.

Installation

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

Linter installation

Before using this plugin, you must ensure that clang is installed on your system. - Mac OS X: clang should be already bundled. - Linux: clang can be easily installed using most package managers. - Windows: the situation is a little trickier, especially with C++. One way to go is to install mingw with clang. Both gcc and clang packages should be installed into the same directory.

Once clang 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 clang you can proceed to install the SublimeLinter-clang 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 clang. Among the entries you should see SublimeLinter-clang. 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-clang provides its own settings.

Setting Description
include_dirs A list of directories to be added to the header search paths (-I is not needed).
extra_flags A string with extra flags to pass to clang. These should be used carefully, as they may cause linting to fail.

In project-specific settings, '$project_folder' or '${project_folder}' can be used to specify relative path.

"SublimeLinter":
{
    "linters":
    {
        "clang": {
            "extra_flags": "-Wall -I${project_folder}/foo",
            "include_dirs": [
                "${project_folder}/3rdparty/bar/include",
                "${project_folder}/3rdparty/baz"
            ]
        }
    }
},

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 clang fails to locate the C++ standard library headers. Assuming the compilation works when executed via command line, try to compile with clang++ -v. This will display all of the hidden flags clang uses. As a last resort, they can all be added as “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 a pull request.
  5. 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 abbrevations unless they are very well known.

Thank you for helping out!