cgcc - Linux


Overview

cgcc is a C/C++ compiler collection that includes several different compilers in a single package. It is designed to support the development of high-performance computing applications, especially on large-scale supercomputers.

Syntax

cgcc [options] file.c [file.o ... ]

Options/Flags

  • -c: Compile only, do not link.
  • -o <output>: Specify the name of the output file.
  • -g: Generate debugging information.
  • -O<level>: Optimize code, with level ranging from 0 (no optimization) to 3 (maximum optimization).
  • -march=<architecture>: Specify the target architecture for the compilation.
  • -I<directory>: Add a directory to the include search path.
  • -L<directory>: Add a directory to the library search path.
  • -l<library>: Link to the specified library.
  • -h: Display help and usage information.

Examples

Simple Compilation

cgcc main.c

This compiles the main.c file and creates an executable named a.out.

Compilation with Optimization

cgcc -O3 -march=native main.c

This compiles main.c with the highest optimization level and targets the native architecture, resulting in a highly optimized executable.

Linking to a Library

cgcc -o myapp main.c -lmylibrary

This compiles main.c and links it to the mylibrary library, creating an executable named myapp.

Common Issues

Missing Libraries

If you encounter errors during linking, you may not have the required libraries installed. Use ldd to identify the missing libraries and install them accordingly.

Incorrect Architecture

Ensure that you specify the correct -march option when targeting a specific architecture. Incorrect architecture selection can lead to incompatibilities and errors.

Integration

cgcc can be integrated with other tools such as:

  • Makefile: Use cgcc as the compiler in your Makefile to automate the compilation process.
  • CMake: Configure CMake to use cgcc as the compiler for your project.
  • MPI: Use cgcc to compile MPI-based applications for parallel computing.

Related Commands

  • gcc
  • clang
  • g++
  • icpc