CLEAR C/C++ Development Environment Guide
Introduction
The CLEAR computing environment provides multiple C and C++ compiler toolchains, including GCC and Clang, to support coursework, software development, and research projects.
This guide explains how to access and use the available compiler environments on the CLEAR systems. Because multiple compiler versions may be available, select the compiler environment appropriate for your course, application, or project.
For most users, it is recommended to enable a compiler environment for the current terminal session rather than permanently modifying the login environment. This helps prevent compiler settings from one course or project from affecting another.
GCC 9.3.1 on CLEAR
GCC 9.3.1
GCC 9.3.1 is available on the CLEAR systems. It is not the system default, so the appropriate environment must be enabled before using this version of GCC or G++.
Quick Start
To enable GCC 9.3.1 for your current terminal session, run:
source /opt/rh/devtoolset-9/enable
You can verify the active compiler version with:
gcc --version
For the C++ compiler, use:
g++ --version
Per Session or Terminal
After establishing an SSH session to a CLEAR system, run:
source /opt/rh/devtoolset-9/enable
This sets the required PATH and environment variables for the current terminal session. If you open another SSH session or close and reopen your terminal, you must run the command again.
Compiling an Application
The following example creates and compiles a simple C program.
Create a file named hello.c:
cat > hello.c <<'EOF'
#include <stdio.h>
int main(void)
{
printf("Hello, world!\n");
return 0;
}
EOF
Create a build script named build-app.sh:
cat > build-app.sh <<'EOF'
#!/usr/bin/env bash
# Enable verbose output when started with:
# DEBUG=true ./build-app.sh
[[ ${DEBUG} ]] && set -xvu
# Enable GCC 9.3.1
source /opt/rh/devtoolset-9/enable
CC='gcc'
# CC='g++' # Uncomment to use G++
${CC} --version
cc_opts="-Wall"
# Compile the application
${CC} ${cc_opts} hello.c -o hello
EOF
Make the script executable:
chmod u+x build-app.sh
Run the build script:
./build-app.sh
For verbose shell output, you can instead run:
DEBUG=true ./build-app.sh
After the application compiles successfully, run it with:
./hello
You should see:
Hello, world!
This example demonstrates the basic process. More complex projects can use tools such as make and project-specific Makefiles while the appropriate compiler environment is enabled.
Permanent Configuration
For most students, enabling the compiler environment only when needed is recommended. This helps prevent one course or project from affecting another.
If you need to determine your current login shell, run:
echo $SHELL
If you choose to configure the compiler environment automatically, add the following command to the appropriate shell initialization file:
source /opt/rh/devtoolset-9/enable
Be aware that permanently enabling a specific compiler version may affect other coursework or applications that expect the system-default compiler.
GCC 11.5.0 From the Red Hat Software Collection
GCC 11.5.0
GCC 11.5.0 is available as a parallel compiler installation on the CLEAR systems. This allows users to access an alternate GCC and G++ toolchain without replacing the compiler supplied by the operating system.
Using the Compiler Wrapper Scripts
Wrapper scripts ending in -SCL are available to simplify access to the alternate compiler environment.
Examples:
gcc-SCL <options> gcc-SCL --version g++-SCL <options> g++-SCL --version
Starting a Shell Session
You can also start a Bash shell with the appropriate development toolset enabled:
exec scl enable devtoolset-13 'bash'
After entering the enabled shell environment, the standard compiler commands can be used directly:
gcc <options> gcc --version g++ <options> g++ --version
This approach may be useful when compiler tools, linkers, debuggers, or other related development utilities need to operate within the same environment.
Additional Documentation
For additional information about GCC Toolset and C/C++ development on Red Hat Enterprise Linux, see the Red Hat GCC Toolset documentation.
Clang 11.0.1 on CLEAR
Clang 11.0.1
Clang 11.0.1 is available on the CLEAR systems. It is not the system default, so the appropriate environment must be enabled before using this version of Clang.
Quick Start
To enable Clang 11.0.1 for your current terminal session, run:
source /opt/rh/llvm-toolset-11.0/enable
Verify the active compiler version with:
clang --version
For the C++ compiler, use:
clang++ --version
Per Session or Terminal
After establishing an SSH session to a CLEAR system, run:
source /opt/rh/llvm-toolset-11.0/enable
This enables the required environment variables for the current terminal session. If you open another SSH session or close and reopen your terminal, you must run the command again.
Compiling an Application
The following example creates and compiles a simple C program using Clang.
Create a file named hello.c:
cat > hello.c <<'EOF'
#include <stdio.h>
int main(void)
{
printf("Hello, world!\n");
return 0;
}
EOF
Create a build script named build-app.sh:
cat > build-app.sh <<'EOF'
#!/usr/bin/env bash
# Enable verbose output when started with:
# DEBUG=true ./build-app.sh
[[ ${DEBUG} ]] && set -xvu
# Enable Clang 11.0.1
source /opt/rh/llvm-toolset-11.0/enable
CC='clang'
# CC='clang++' # Uncomment to use Clang++
${CC} --version
cc_opts="-Wall"
# Compile the application
${CC} ${cc_opts} hello.c -o hello
EOF
Make the script executable:
chmod u+x build-app.sh
Run the build script:
./build-app.sh
For verbose shell output, you can instead run:
DEBUG=true ./build-app.sh
After the application compiles successfully, run it with:
./hello
You should see:
Hello, world!
Permanent Configuration
For most students, enabling the Clang environment only when needed is recommended. This helps prevent compiler settings from affecting other courses or applications.
If you choose to configure the Clang environment automatically, add the following command to the appropriate shell initialization file:
source /opt/rh/llvm-toolset-11.0/enable
Be aware that permanently enabling a specific compiler environment may affect applications that expect the system-default compiler.