In this tutorial, you will install the Eclipse 4.4.2 (Luna) IDE and the GNU Compiler Collection 4.9.2 from the Red Hat Developer Toolset (DTS) and build a simple C++ Hello World application. This tutorial should take less than 30 minutes to complete.
Red Hat DTS provides the latest, stable, open source C and C++ compilers and complementary development tools, including Eclipse. DTS enables developers to compile applications once and deploy across multiple versions of Red Hat Enterprise Linux.
You will need a Red Hat Enterprise Linux 6 system with a current Red Hat subscription that allows you to download software and updates from Red Hat. Access to the Red Hat Software Collections (RHSCL) is included with many Red Hat Enterprise Linux (RHEL) subscriptions. For more information about which subscriptions include RHSCL, see How to use Red Hat Software Collections (RHSCL) or Red Hat Developer Toolset (DTS).
If you don’t have a Red Hat Enterprise Linux subscription, you can try it for free. Get started with an evaluation at https://access.redhat.com/products/red-hat-enterprise-linux/evaluation. Select the Red Hat Enterprise Linux Developer Workstation option to ensure your evaluation will include both RHSCL and DTS.
If you encounter difficulties at any point, see Troubleshooting and FAQ.
In this step, you will configure your system to obtain software, including the Red Hat DTS, latest dynamic languages, and open source databases from the Red Hat Software Collection repository. Instructions are provided for both the command line (CLI) and graphical user interface (GUI).
Red Hat Subscription Manager can be started from the System → Administration subgroup of the Applications menu. Alternatively, you can start it from the command prompt by typing subscription-manager-gui
.
-
On the Subscription Manager System menu, select Repositories.
-
In the list of repositories, check the Enabled column for rhel-server-rhscl-6-rpms and rhel-6-server-optional-rpms. If you are using a desktop version of Red Hat Enterprise Linux, the repositories will be named rhel-desktop-rhscl-6-rpms and rhel-6-desktop-optional-rpms. Note: After clicking, it might take several seconds for the check mark to appear in the enabled column.
If you don’t see any RHSCL repositories in the list, your subscription might not include it.
See Troubleshooting and FAQ for more information.
You can add or remove software repositories from the command line using the subscription-manager
tool as the root user. Use the --list
option to view the available software repositories and verify that you have access to RHSCL, which includes DTS:
$ su -
# subscription-manager repos --list | egrep rhscl
If you don’t see any RHSCL repositories in the list, your subscription might not include it. See Troubleshooting and FAQ for more information.
If you are using a desktop edition of Red Hat Enterprise Linux, change -server-
to -desktop-
in the following commands:
# subscription-manager repos --enable rhel-server-rhscl-6-rpms
# subscription-manager repos --enable rhel-6-server-optional-rpms
In this next step you will use a single command to download and install Eclipse 4.4.2, GCC 4.9.2, and other development tools from the Red Hat DTS. The length of time this step takes depends on the speed of your Internet connection and your system. With a reasonably fast connection, this step should complete in well under 5 minutes.
$ su -
# yum install devtoolset-3
If you prefer, you can skip installing the Eclipse IDE, and select only the GCC tool chain. This will result in a much faster download and installation.
$ su -
# yum install devtoolset-3-toolchain
Note: You will still use devtoolset-3
as the name of the software collection in all scl
commands. Only the name of the meta-package to be installed by yum
changes.
Start the Eclipse IDE by selecting DTS Eclipse from the Programming section of the desktop Applications menu. Note: The first launch of Eclipse under your user ID might take a minute or two longer to start up than normal.
When Eclipse starts, it will prompt you to select a workspace folder. Click OK to select the default location in your home directory.
Note: If you prefer to start Eclipse from the command line use the following command:
$ scl enable devtoolset-3 eclipse
See Permanently adding DTS to your Development Environment for more information.
The following steps will create and run a C++ Hello World project using the samples included with Eclipse’s C/C++ Development Toolkit (CDT). Note: If you need help, select Help → Help Contents from Eclipse’s menu. Expand the C/C++ Development User Guide and select Getting Started.
-
On the Eclipse File menu, select New → Project.
-
In the New Project dialog, expand the C/C++ section, click C++ Project, then click Next.
-
In the C++ Project dialog, do the following:
-
In the Project Name field, type
HelloWorld
. -
Under Executables, click Hello World C++ Project.
-
Under Toolchains, click Linux GCC.
-
Click Next.
-
-
On the Basic Settings dialog:
-
In the Author field, type your name.
-
In the Hello World greating field, type
Hello, Red Hat Developers World
. -
Click Finish.
-
-
In the Open Associated Perspective? dialog, click Yes.
-
Close the Welcome tab. This will reveal the C/C++ development perspective.
-
In the lower half of the Eclipse window, click on the Console tab.
-
On the Eclipse Project menu, select Build All to build the project.
-
On the Eclipse Run menu, select Run Configurations…
-
On the Run Configurations dialog:
-
Select C/C++ Application on the left.
-
Click the New button in the upper left.
-
Click the Run button.
You will see "Hello, Red Hat Developers World" in the Console tab on the lower half of the Eclipse window. You may want to make the Eclipse window larger, or make the Console pane larger to see more of the output from the build and run steps.
-
For more information, see the Using Eclipse section of the Red Hat Developer Toolset 3.1 User Guide.
If you skipped installing Eclipse or prefer to work in a Terminal window, you can run the DTS GNU C++ compiler from the command line. The GNU C++ compiler is run with the command, g++
. You need to add DTS to your environment with scl enable
in a Terminal window. Also see Permanently adding DTS to your Development Environment for more information.
$ scl enable devtoolset-3 bash
Now create hello.cpp
using your preferred text editor or simply use cat
:
$ cat > hello.cpp
#include <iostream>
using namespace std;
int main(int argc, char *argv[]) {
cout << "Hello, Red Hat Developers World!" << endl;
return 0;
}
Type control-d
to exit cat
, or if you used an editor save the file and exit.
Now compile and run the program:
$ g++ -o hello hello.cpp
$ ./hello
Hello, Red Hat Developers World!
For more information, see the GNU C++ Compiler section of the Red Hat Developer Toolset 3.1 User Guide.
The Red Hat Developer Toolset is delivered as a set of packages in the Red Hat Software Collection. The software packages in RHSCL are designed to allow multiple versions of software to be installed concurrently. To accomplish this, the desired package is added to your runtime environment as needed with the scl enable
command. When scl enable
runs, it modifies environment variables and then runs the specified command. The environmental changes only affect the command that is run by scl
and any processes that are run from that command. The steps in this tutorial run the command bash
to start a new interactive shell to work in the updated environment. The changes aren’t permanent. Typing exit
will return to the original shell with the original environment. Each time you login, or start a new terminal sesssion, scl enable
needs to be run again.
While it is possible to change the system profile to make RHSCL packages part of the system’s global environment, this is not recommended. Doing this can cause conflicts and unexpected problems with other applications because the system version of the package is obscured by having the RHSCL version in the path first.
To make DTS a permanent part of your development environment, you can add it to the login script for your specific user ID. This is the recommend approach for development, because only processes run under your user ID will be affected.
Using your preferred text editor, add the following line to the end of ~/.bashrc
:
source scl_source enable devtoolset-3
After logging out and logging back in again, you can verify that the DTS GCC is in your path by running which g++
or g++ -v
.
$ which g++
/opt/rh/devtoolset-3/root/usr/bin/g++
$ g++ -v
gcc version 4.9.2. 20150212 (Red Hat 4.9.2-6) (GCC)
Learn more about Eclipse and the GNU Compiler Collection from the Red Hat Developer Toolset
Documentation and tutorials for C/C++ development using Eclipse
Learn more about the Red Hat Developer Toolset
Learn more about Red Hat Software Collections
Red Hat Software Collections deliver the latest stable versions of dynamic languages, open source databases, and web development tools that can be deployed alongside those included in Red Hat Enterprise Linux. Red Hat Software Collections is available with select Red Hat Enterprise Linux subscriptions and has a three-year life cycle to allow rapid innovation without sacrificing stability.
For more information:
-
Red Hat Software Collections 2.0 Packaging Guide — The packaging guide for Red Hat Software Collections explains the concept of software collections, documents the
scl
utility, and provides a detailed explanation of how to create a custom software collection or extend an existing one. -
Red Hat Software Collections 2.0 Release Notes — The release notes for Red Hat Software Collections document known problems, possible issues, and other important information available at the time of release of the content set. They also contain useful information on installing, rebuilding, and migrating.
-
How to use Red Hat Software Collections (RHSCL) or Red Hat Developer Toolset (DTS) — This article lists which Red Hat Enterprise Linux subscriptions include access to Red Hat Software Collections and the Developer Toolset.
You can view the list of packages available in RHSCL by running:
$ yum --disablerepo="*" --enablerepo="rhel-server-rhscl-6-rpms" list available
Developing with Red Hat Enterprise Linux
Red Hat Enterprise Linux 6 Developer Guide — The developer guide for Red Hat Enterprise Linux 6 provides an introduction to application development tools and using source code management tools such as Git in Red Hat Enterprise Linux 6.
You may also want to view the Red Hat Enterprise Linux 7 Developer Guide for updated information. Red Hat Enterprise Linux 7 was released in 2014.
Red Hat delivers the resources and ecosystem of experts to help you be more productive and build great solutions. Register for free at developers.redhat.com.
-
The RHSCL repository is not available or is not found on my system.
The name of the repository depends on whether you have a server or desktop version of Red Hat Enterprise Linux installed.
Some Red Hat Enterprise Linux subscriptions do not include access to RHSCL. See How to use Red Hat Software Collections (RHSCL) or Red Hat Developer Toolset (DTS).
-
yum install devtoolset-3
fails due to a missing RPM dependency.These packages are in the optional RPMs repository, which is not enabled by default. See [Enable Red Hat Software Collections] for how to enable both the optional RPMs and RHSCL repositories.
-
When I try to start Eclipse, I get a message about the Eclipse Platform not responding.
The first launch of Eclipse under your user ID might take a minute or two longer to start up than normal while Eclipse sets up files in your home directory. Click the Wait button to let Eclipse finish starting up.
-
The Eclipse C++ perspective never opens, all I see is "Welcome to Eclipse".
The Welcome tab in Eclipse obscures any of the other tabs. Click the X to close the Welcome tab.
-
Which version of GCC am I using?
I’m getting the older GCC that came with Red Hat Enterprise Linux instead of the newer DTS version.
How do I include the DTS GCC in my path?
The Red Hat Developer Toolset uses Red Hat Software Collections to install a parallel set of packages in
/opt/rh
where they will not override the system packages that come with Red Hat Enterprise Linux.Use
which g++
to see which compiler is in your path. The DTS gcc executable path will begin with/opt/rh
. Alternatively, useg++ -v
to confirm that the version number is the correct one for Red Hat Developer Toolset.$ which g++ /opt/rh/devtoolset-3/root/usr/bin/gcc $ g++ -v gcc version 4.9.2. 20150212 (Red Hat 4.9.2-6) (GCC)
If
which
returns/usr/bin/g++
, org++ -v
shows a different version, you need to runscl enable
to add DTS GCC and the rest of DTS to your environment.$ scl enable devtoolset-3 bash
-
How can I view the manual pages for the DTS version of GCC?
When you use
scl enable
, the manual page search path, MANPATH, is updated. This is in addition to the other environment variables that are updated which include PATH, and LD_LIBRARY_PATH.$ scl enable devtoolset-3 bash $ man g++
Note: It is possible to use
scl enable
for a specific command. This might be handy if you want to compare the manual page differences between versions.$ scl enable devtoolset-3 'man g++'
-
How do I find out which other packages are available in the Red Hat Developer Toolset?
You can view the list of packages with the following command:
# yum list available devtoolset-3-\*
-
How can I find out what RHSCL packages are installed?
scl --list
will show the list of RHSCL packages that have been installed, whether they are enabled or not.$ scl --list rh-perl520 rh-php56 rh-python34 rh-ruby22
-
Why did Java get installed for doing C++ development?
The Eclipse IDE is Java based and needs a Java runtime environment. When Eclipse is installed from DTS, the software collection rh-java-common will be installed automatically.