SE 2040 Eclipse CDT How-Tos
See here for installation directions.
Note: some of the directions below are for pre-2019 versions of
Eclipse and are in the process of being updated.
Configuration
- Temporarily changing the font size for
presentations:
Press Control-Shift-+ to increase the font size, Control--
(control-minus) to decrease it.
- Turning off hard tabs:
- Windows | Preferences
- General | Editors | Text Editors | check Insert spaces for tabs
- C/C++ | Code Style | Formatter; click the New button to create a
new profile, then OK to continue. The system will pop up a
formatting dialog; on the Indentation tab, change the policy to
"Spaces only"
- Making C++14 the default for the editor:
- Windows | Preferences
- Expand C/C++, Build, and select Settings
- Select the Discovery tab
- Click on CDT Cross GCC Built-in Compiler Settings
- In the Command to get compiler specs box, add the following
before "${INPUTS}":
-std=c++14
- Set GCC to be the default compiler for new projects:
- Windows | Preferences
- C/C++ | New C/C++ Project Wizard
- In Project type, select Executable
- in Toolchains, select MinGW GCC
- Click on the button Make toolchain(s) preferred
- Improving the behavior when you run or debug
programs:
- Windows | Preferences
- Expand Run/Debug and Launching
- Set Continue launch if project contains errors
to Prompt
- In Launch Operation, select Launch the associated
project and Terminate and Relaunch while launching
- Adding a margin line to identify long lines
- Windows | Preferences
- General | Editors | TextEditors
- Check Show print margin and set the margin to the
appropriate number.
Creating New C++ Projects
- File | New | C++ Project, select
Hello World C++ Project, MinGW GCC
and set the project name. There should be no spaces in the name.
- To control where your project is located,
deselect Use default location and browse to where you
want your project files to be located. This is more robust than
placing them in the workbench, and helps tremendously when browsing
to the project outside of Eclipse.
- If MinGW GCC is not an option when you create a new project,
create the mingw32-gcc.exe
file and restart Eclipse.
- To enable modern C++ features,
- Project | Properties
- Expand C/C++ Build and click on Settings
- Under GCC C++ Compiler click on Dialect
- Set the Language standard to ISO C++1y
- Click OK
Running Programs from Eclipse
- If there is a build error about not being able to access the
executable, try killing the debugging sessions:
- Window | Open Perspective | Debug (or click on
the debug icon in the Quick Access area)
- Right click in the Debug area (upper left) and
select Terminate/Disconnect All or Terminate and Remove
- If there is a build error like
"Function 'stoi' could not be resolved",
- Project | Clean...
- Project | Build Project
- To redirect standard input to read from a file,
- Run | Run Configurations...
- Select the project (if necessary)
- Common tab
- Check Input File
- Use the File System... button to select the input
- Select Apply and then close the configuration manager
Note you can also save different input file settings as different run
configurations; see the next entry.
- Setting command-line arguments:
- Run | Run Configurations...
- Select C/C++ Application and click on
the icon to
create a new configuration
- Click on the Arguments tab and enter the argument such as
-f myfile.xyz
- Rename the configuration to something like "use myfile" so that you
can keep it separate from other configurations
- Select the Common tab and check the entries for Debug
and Run in the
Display in favorites menu box
- Select Apply and then close the configuration manager.
You can then select the new run configuration from the dropdowns next to
the debug and run icons .