Yup there's a way. Sublime Text is just a text editor like a more advanced form of Textedit on the mac. You can not compile code with it like you do in xcode. You can write it in Sublime Text and then compile it with Terminal. Mac OS X: code 'c. ⭐ Kite is a free AI-powered coding assistant that will help you code faster and smarter. The Kite plugin integrates with all the top editors and IDEs to give. Step 1: Download the.dmg file of Sublime Text from the official website just like we did for windows. Step 2: run and install the file and then you are ready to go. Now, you need to install the Gcc compiler on your mac.
C/C++ language servers
The below was written for clangd, but much applies to cquery and ccls as well.
CCLS
A newer project emerged from cquery.Build and install from source, see ccls wiki
Cquery
![Sublime Text C++ Compiler Mac Sublime Text C++ Compiler Mac](/uploads/1/1/9/8/119878085/611984644.jpg)
Build and install from source, see cquery wikiNote that work on cquery has stopped. Prefer using ccls or clangd.
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:And if you're on macOS 10.14, also run the following to install essential headers like
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.
Sublime Text C
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 called
compile_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.![Sublime Text C++ Compiler Mac Sublime Text C++ Compiler Mac](/uploads/1/1/9/8/119878085/649258628.png)
If you are using a make-based build system, you could use compiledbto generate a
compile_commands.json
.Sublime Text C++ Compiler
Since header files are (usually) not passed to a compiler, they don't havecompile commands. 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.
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.