Clang is the compiler built by Apple to compile C and a bunch of other languages. Or you can download Sublime Text. (this is our current favourite text editor). How to learn C in Mac OS X. 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.
New instructions: https://chromium.googlesource.com/chromium/src/+/master/docs/sublime_ide.mdContents
- 9 Example plugin
Contents
- 9 Example plugin
What is Sublime Text?
- Project support.
- Theme support.
- Works on Mac, Windows and Linux.
- No need to close and re-open during a
gclient sync
. - Supports many of the great editing features found in popular IDE's like Visual Studio, Eclipse and SlickEdit.
- Doesn't go to lunch while you're typing.
- The UI and keyboard shortcuts are pretty standard (e.g. saving a file is still Ctrl+S on Windows).
- It's inexpensive and you can evaluate it (fully functional) for free.
Installing Sublime Text 2
Preferences
'tab_size': 2,
Project files
'folders':
{
}
}
'folders':
{
'name': 'src',
'*.vcproj',
'*.sln',
'*.gitmodules',
],
'build',
'third_party',
'Debug',
]
]
Navigating the project
- 'Goto Anything' or Ctrl+P is how you can quickly open a file or go to a definition of a type such as a class. Just press Ctrl+P and start typing.
- Open source/header file: If you're in a header file, press Alt+O to open up the corresponding source file and vice versa. For more similar features check out the Goto->Switch File submenu.
- 'Go to definition': Right click a symbol and select 'Navigate to Definition'. A more powerful way to navigate symbols is by using the Ctags extension and use the Ctrl+T,Ctrl+T shortcut. See the section about source code indexing below.
Enable source code indexing
- Install the Sublime Package Control package: https://packagecontrol.io/installation
- Install Exuberant Ctags and make sure that ctags is in your path: http://ctags.sourceforge.net/
- On linux you should be able to just do: sudo apt-get install ctags
- Install the Ctags plugin: Ctrl+Shift+P and type 'Package Control: Install Package'
- Create a batch file (e.g. ctags_builder.bat) that you can run either manually or automatically after you do a gclient sync:This takes a couple of minutes to run, but you can work while it is indexing.
ctags --languages=C++ --exclude=third_party --exclude=.git --exclude=build --exclude=out -R -f .tmp_tags & ctags --languages=C++ -a -R -f .tmp_tags third_partyplatformsdk_win8 & ctags --languages=C++ -a -R -f .tmp_tags third_partyWebKit & move /Y .tmp_tags .tags
- Edit the CTags.sublime-settings file for the ctags plugin so that it runs ctags with the above parameters. Note: the above is a batch file - don't simply copy all of it verbatim and paste it into the CTags settings file :-)
Windows: git config --global core.excludesfile %USERPROFILE%.gitignore
Mac, Linux: git config --global core.excludesfile ~/.gitignoreBuilding with ninja
'cmd': ['ninja', '-C', 'outDebug', 'chrome.exe'],
'file_regex': '^[./]*([a-z]?:?[w./]+)[(:]([0-9]+)[):,]([0-9]+)?[:)]?(.*)$'
You can also add build variants so that you can also have quick access to building other targets like unit_tests or browser_tests. You build description file could look like this:
And keep using 'ctrl+b' for a regular, 'chrome.exe' build. Enjoy!
Example plugin
import subprocess
class RunLintCommand(sublime_plugin.TextCommand):
command = ['cpplint.bat', self.view.file_name()]
stdout=subprocess.PIPE,
print process.communicate()[1]
{
}
D:srccgitsrccontentbrowserbrowsing_instance.cc:69: Add #include <string> for string [build/include_what_you_use] [4]
Done processing D:srccgitsrccontentbrowserbrowsing_instance.cc
Sublime Text C++ Compiler Machine
['__class__', '__delattr__', '__dict__', '__doc__', '__format__', '__getattribute__', '__hash__', '__init__', '__len__', '__module__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', 'add_regions', 'begin_edit', 'buffer_id', 'classify', 'command_history', 'em_width', 'encoding', 'end_edit', 'erase', 'erase_regions', 'erase_status', 'extract_completions', 'extract_scope', ... <snip>
Compile current file using Ninja
As a more complex plug in example, look at the attached python file: compile_current_file.py. This plugin will compile the current file with Ninja, so will start by making sure that all this file's project depends on has been built before, and then build only that file.
First, it confirms that the file is indeed part of the current project (by making sure it's under the <project_root> folder, which is taken from the self.view.window().folders() array, the first one seems to always be the project folder when one is loaded). Then it looks for the file in all the .ninja build files under the <project_root>out<target_build>, where <target_build> must be specified as an argument to the compile_current_file command. Using the proper target for this file compilation, it starts Ninja from a background thread and send the results to the output.exec panel (the same one used by the build system of Sublime Text 2). So you can use key bindings like these two, to build the current file in either Debug or Release mode:
{ 'keys': ['ctrl+f7'], 'command': 'compile_current_file', 'args': {'target_build': 'Debug'} },
{ 'keys': ['ctrl+shift+f7'], 'command': 'compile_current_file', 'args': {'target_build': 'Release'} },
If you are having trouble with this plugin, you can set the python logging level to DEBUG in the console and see some debug output.
Format selection (or area around cursor) using clang-format
Sublime Text C++ Plugin
Miscellaneous tips
- To synchronize the project sidebar with the currently open file, right click in the text editor and select 'Reveal in Side Bar'. Alternatively you can install the SyncedSideBar sublime package (via the Package Manager) to have this happen automatically like in Eclipse.
- If you're used to hitting a key combination to trigger a build (e.g. Ctrl+Shift+B in Visual Studio) and would like to continue to do so, add this to your Preferences->Key Bindings - User file:
- { 'keys': ['ctrl+shift+b'], 'command': 'show_panel', 'args': {'panel': 'output.exec'} }
- Install the Open-Include plugin (Ctrl+Shift+P, type:'Install Package', type:'Open Include'). Then just put your cursor inside an #include path, hit Alt+D and voila, you're there.
- If you want to take that a step further, add an entry to the right-click context menu by creating a text file named 'context.sublime-menu' under '%APPDATA%Sublime Text 2PackagesUser' with the following content:
[ { 'command': 'open_include', 'caption': 'Open Include' } ]
- Open Command Palette (Ctrl-Shift-P)
- Type 'Package Control: Install Package' (note: given ST's string match is amazing you can just type something like 'instp' and it will find it :-)).
- Case Conversion (automatically swap casing of selected text -- works marvel with multi-select -- go from a kConstantNames to ENUM_NAMES in seconds)
- CTags (see detailed setup info above).
- Git
- Open-Include
- Text Pastry (insert incremental number sequences with multi-select, etc.)
- Wrap Plus (auto-wrap a comment block to 80 columns with Alt-Q)
This tutorial will guide you through the process of installing, updating, and initial configuration of CLion on macOS.
Installation procedures
Before you start the CLion installation on macOS, make sure your machine meets the hardware requirements, and the version of your macOS is 10.9.4+.
You can always have multiple instances of CLion installed on the same OS, including both release and EAP builds.
Download the latest release or EAP version of CLion for macOS (earlier versions are available on the Previous CLion Releases page).
Open the downloaded CLion-*.dmg package and drag CLion to the Applications folder.
Open the Applications folder and launch the CLion installer.
If the security warning appears, agree to open the application:
When you install CLion manually, the update checking is performed automatically by default (every time the IDE is ready to update, you will see a message in the status bar). To configure the update process, go to Preferences | Appearance and Behaviour | System Settings | Updates and select the update channel:
Click Check now to perform the checking right away. In case there are available updates according to the chosen channel, you will see a dialog like the following:
Toolbox is a control panel that allows you to manage all JetBrains developer tools, including CLion, as well as your projects, from a single point of access. It enables you to maintain different versions of CLion, install updates and roll them back if needed. Toolbox remembers your JetBrains Account and uses it to automatically log in when you install and register new tools.
Download Toolbox and launch the setup file.
When the installation is complete, accept the JetBrains privacy policy and sign in to your JetBrains Account.
Now you can choose which version of CLion to install:
Toolbox shows the list of the installed versions:
In the Settings dialog, configure the way of updating CLion:
Note that in case of using Toolbox, the update process cannot be configured from within the IDE. The Preferences | Appearance and Behaviour | System Settings | Updates dialog shows the following message:
Alternatively, you can install CLion via the Homebrew package manager : brew cask install clion
. However, this option is unofficial, as the CLion team is not involved in its maintenance or support.
After the installation or upgrade, you will be prompted to import, inherit, or create new settings for the IDE.
Required tools
CLion needs to be provided with C and C++ compilers and the make utility. These tools may be pre-installed on your system: check it in Preferences | Build, Execution, Deployment | Toolchains- the compiler and make detection should perform successfully.
If your system does not have working installations of compilers and make, the simplest solution is to install Xcode command line developer tools.
Run the following command:
When prompted to install command line developer tools, click the Install button:
You can also choose to install the full package of Xcode, though it is not necessary for CLion.
With Xcode command line tools, you get the Clang compiler installed by default. To check the compiler presence and its version, run clang --version
.
Command line tools may not update automatically along with the system or Xcode update. This may cause error messages like invalid active developer path during project loading in CLion. To fix this, run the same xcode-select --install
command, and the tools will be updated accordingly.
As an alternative, you can separately install compilers and make, and then provide the paths in Preferences | Build, Execution, Deployment | Toolchains.
Note that you can use multiple compilers for the needs of your project, see Switching Compilers.
Configure toolchains
Now you need to configure the toolchain to work with, which means choosing the CMake executable, the make and C/C++ compilers location, and the debugger. Navigate to Preferences | Build, Execution, Deployment | Toolchains and edit the default toolchain, or click to add a new one.
CMake, make, and compilers
In the CMake field, specify the CMake binary that you want to use. You may stick to the bundled CMake, or use your custom CMake executable (see the minimum supported version in Software requirements).
The chosen CMake attempts to detect the compilers and make considering the packages installed on your system. If the detection succeeds, the fields Make, C Compiler, and C++ Compiler are filled automatically:
The detection of compilers and make fails if CMake cannot locate the appropriate tools (this may happen, for instance, if you installed them separately without the Xcode developer tools). In this case, you need to provide the actual paths manually.
Debugger
CLion for macOS comes with the bundled LLDB v 12.0.0 (the default debugger) and GDB v 10.2. You can also switch to a custom GDB (supported versions are 7.8.x-8.1.x). Select the debugger in Preferences | Build, Execution, Deployment | Toolchains:
Issues are possible when working with both bundled or custom GDB on macOS. To improve the behavior, enable the cidr.debugger.gdb.workaround.macOS.startupWithShell option in Registry (select Help | Find Action from the main menu and type Registry):
Note that enabling this option is not equivalent to setting set startup-with-shell off
in your .gdbinit script.
A combination of GDB and Clang implies certain limitations to debugging your projects on macOS. See STL renderers for GDB on macOS for details and a workaround.
Further steps
Now that you have CLion installed and configured, you may find the following articles useful for further steps of the development: