The biggest problem of C++ code is bugs. Bugs can slip through even when compiling code with all warnings turned on. A useful tool in the arsenal of a C++ programmer is CPPCheck, a static analysis tool. You are in luck if you are using Eclipse CDT because the CPPChEclipse plugin makes using CPPCheck with your C++ project very easy.
Go to Window -> Preferences -> C/C++ -> CPPChEclipse. First, set the path of CPPCheck to /usr/bin/cppcheck. In the Problems subsection, choose the types of problems you want to be reported about (warnings, errors, style problems). In the Settings subsection, choose the C and C++ standard versions you want to be applied. You can also indicate the CPPCheck use the include paths used by your project (this is very useful).
To run CPPCheck on a project, right-click on its name in the Project Explorer and choose CPPCheck -> Run CPPCheck. The default keyboard shortcut for this is Shift + Ctrl + C. After CPPCheck runs, you can view the problems it has reported in the Problems view at the bottom of Eclipse.
Eclipse has no option to display in full screen mode! By full screen mode, we mean that Eclipse occupies the entire display, with the Dash (on the left) and Panel (on the top) hidden. This is typically achieved in other applications by pressing F11. Note that, there is a maximize mode where the current Edtitor window is maximized, but this is different from full screen.
Zeal is an offline documentation browser which can be used to lookup help for most popular libraries and APIs. The ZealLookup plugin (also called ZealEclipsePlugin) enables you to lookup help in Zeal right from inside Eclipse! 🙂
Download the plugin .jar file from here and place it in the plugins directory of your Eclipse installation.
You need to configure a keyboard shortcut for ZealLookup. Go to Window -> Preferences -> General -> Keys. Look for Lookup in Zeal command and set a keyboard shortcut for it.
To lookup a word in Zeal: highlight the word and press the keyboard shortcut you have set earlier. Zeal should open with the documentation for the word. I found that sometimes Zeal stays in the background, but it has looked up the word.
For use with Vrapper, I mark the current word using viw (visually mark inner word) and then press the ZealLookup keyboard shortcut.
Tried with: ZealLookup 1.0.0, Eclipse 4.4.2 and Ubuntu 14.04
The include graph of a large C++ project can be really gnarly. Sometimes, you end up with compile errors due to circular inclusion of types or headers and cannot figure out the origin of the error. Other times, you might want to know the path of header files through which a certain type is available in a source file. To view these details, I generate a header include graph using Doxygen.
However, if you are using Eclipse CDT you have something that is easier and more convenient: its Include Browser! 🙂
To open it: Go to Window -> Show View -> Include Browser. It will typically be displayed at the bottom of Eclipse.
To view the include graph of a source or header file: Go to the Project Explorer, find the file and drag its name into the Include Browser window.
By default, the include graph of the includes of the file are displayed.
You can also view which other files include the current file.
If the include graph is too cluttered, you can disable display of system includes. These are typically standard C++ header files.
You can also disable display of includes in inactive code.
Setting a mark using Vrapper is the same as in Vim. Press the m key followed by a lowercase or uppercase letter.
There is a slight difference. If you use a lowercase letter, the mark is set as an invisible mark, like in Vim. However, if you use an uppercase letter, the mark is also set as an Eclipse bookmark. It even appears in the bar on the left as a visual bookmark. Bookmarks set this way can also be viewed by using the Bookmarks view.
Tried with: Vrapper 0.52.1, Eclipse 4.4.1 (Luna) and Ubuntu 14.04
The Project Explorer and Outline views in Eclipse have a Link with Editor feature that can be very useful. This can be enabled in either view, by clicking the down arrow button in the view and choosing Link with Editor (see screenshot above).
If Link with Editor is enabled in Project Explorer: The current file open in the Editor will be highlighted in Project Explorer.
If Link with Editor is enabled in Outline: The class or method at the location of the cursor will be highlighted in Outline.
Prof. Sedgewick has written a popular Algorithms book and developed Algorithms I and II courses on Coursera. Both of these use Java and provide many source code files and assignments to the students. These have been developed for the Dr. Java IDE or to work from the commandline. If you prefer to work with Eclipse for this book or course, just follow these steps:
Install a Java SDK:
$ sudo apt install openjdk-7-jdk
Install Eclipse. Ubuntu ships with old versions of Eclipse. I prefer to install the latest from the Eclipse Downloads webpage. Get the one named Eclipse IDE for Java Developers.
Create a directory named algs4 anywhere under your home directory. This directory will be used to store the packages and configuration files required to work with this book or course.
Download the algs4.jar and stdlib.jar packages to the algs4 directory. These include the classes and methods you will need to work on the assignments.
Install the FindBugs plugin as described here. This will be useful to check your assignment code for bugs before you submit them. Download the findbugs.xml filter file to your algs4 directory. In the FindBugs preferences dialog, add this file as an Exclude filter file.
Install the CheckStyle plugin as described here. Your assignment submission has to adhere to the coding standard of this book or course and this plugin makes it easy to check that. Download the checkstyle.xml configuration file to your algs4 directory. Add this configuration file in the CheckStyle preferences.
Using this CheckStyle configuration file in Eclipse gave me these errors:
cannot initialize module TreeWalker - Unable to instantiate RedundantThrows
cannot initialize module TreeWalker - Unable to instantiate JUnitTestCase
I removed the lines in checkstyle.xml that used these modules and it worked after that. My version of this configuration file can be downloaded here.
You are now ready to work on the assignments! 🙂 Create a new Java project in Eclipse to work on each new assignment. Use the algs4.jar and stdlib.jar packages in the project by adding them in Properties -> Java Build Path -> Libraries -> Add External JARs.
Each assignment provides a barebones template of one or more Java classes. Choose New -> Java class to create a new Java file for each of these classes under the project for that assignment.
Important: When creating the Java class, make sure the Package entry is empty. This puts it under the default package. This is required since the algs4.jar and stdlib.jar also provides their classes under the default package. If you do not do this, you will get a cannot be resolved to a type error when you try to use any of the classes from this course.
Eclipse automatically compiles the code whenever you save the file. So, you can run the code as soon as you are done writing the code. Make sure to run the CheckStyle and FindBugs before you submit your code.