Sublime Text C++ Compiler Mac

Posted on  by 

  • Sublime Text can now utilize your GPU on Linux, Mac and Windows when rendering the interface. This results in a fluid UI all the way up to 8K resolutions, all while using less power than before.
  • All global configuration for Sublime (including installed packages) is stored in /.config/sublime-text-3 (or%APPDATA Sublime Text 3 on Windows, or /Library/Application Support/Sublime Text 3 on Mac). We will reference the Linux folder for the rest of this tutorial, but replace with your own path if using a different OS.

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.

For the Mac people, it meant that they didn’t know how what tool to use apart from X-Code which of course didn’t work (but it did for C) and me, it meant that I had to find a way to compile my code written in mere text editors like Atom or Sublime.

Sublime

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++.

TextSublime text c++ compiler machine

Then go to C++ Single file.

Text

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

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

Coments are closed