Command documentation sourced from the linux-command project This comprehensive command reference is part of the linux-command documentation project.
c99 - Standard C Language Compiler
The c99 command is a standard C language compiler that complies with the IEEE Std 1003.1-2001 ("POSIX.1") standard. It provides a standardized interface for compiling C source files according to the C99 standard (ISO/IEC 9899:1999). The c99 command is essentially a wrapper around the system's C compiler (typically GCC or Clang) that ensures C99 compliance and provides consistent behavior across different UNIX-like systems. It handles preprocessing, compilation, assembly, and linking phases of C program development, making it ideal for portable C development and POSIX-compliant builds.
Basic Syntax
c99 [-cEgs] [-D name[=value]] [-I directory ...] [-L directory ...]
[-o outfile] [-O optlevel] [-U name ...] [-W 32|64] operand ...
Common Options
Compilation Control
-c- Suppress linking phase, compile only to object files-E- Run preprocessor only, output to stdout-g- Produce debugging information in object/executable files-s- Strip symbolic information from executables
Preprocessor Options
-D name[=value]- Define macro with optional value (defaults to 1)-U name- Undefine macro-I directory- Add directory to header file search path
Linking Options
-L directory- Add directory to library search path-l library- Link with specified library
Output Options
-o outfile- Specify output filename-O optlevel- Set optimization level (0 = no optimization)
Architecture Options
-W 32|64- Set pointer size to 32 or 64 bits
Usage Examples
Basic Compilation
Simple Program Compilation
# Compile and link a single C file
c99 program.c
# Compile with custom output name
c99 -o myapp program.c
# Compile only to object file
c99 -c program.c
# Compile with debugging information
c99 -g program.c
# Compile with optimizations
c99 -O2 program.c
Multiple File Compilation
# Compile multiple source files
c99 main.c utils.c helpers.c
# Compile with custom output
c99 -o application main.c modules/*.c
# Compile to object files first
c99 -c main.c utils.c helpers.c
c99 -o program main.o utils.o helpers.o
# Compile with specific library paths
c99 -L/usr/local/lib -o app main.c -lm -lpthread
Preprocessor Operations
Macro Definitions
# Define macros during compilation
c99 -DDEBUG -DVERSION=2.1 program.c
# Define POSIX compliance
c99 -D_POSIX_C_SOURCE=200112L program.c
# Define feature test macros
c99 -D_XOPEN_SOURCE=600 program.c
# Multiple definitions
c99 -DDEBUG -DVERBOSE -DPROGRAM_NAME="myapp" program.c
# Conditional compilation
c99 -DTESTING -DBENCHMARK program.c
Header File Management
# Add include directories
c99 -I./include -I/usr/local/include program.c
# Multiple include paths
c99 -Iinc -I../shared -I/opt/lib/include program.c
# System and local includes
c99 -I./local_include -I/usr/include program.c
# Compile with specific header search order
c99 -I./headers -I../common program.c
Library Linking
Standard Libraries
# Link with math library
c99 -o calculator calc.c -lm
# Link with pthread library
c99 -o server server.c -lpthread
# Link with multiple libraries
c99 -o app app.c -lm -lpthread -lsocket
# Link with networking libraries
c99 -o network_client client.c -lsocket -lnsl
# Link with database libraries
c99 -o db_app db_app.c -lsqlite3 -lpthread
Custom Library Paths
# Link with custom library directory
c99 -L./lib -o app app.c -lmylib
# Multiple library directories
c99 -L./lib -L/usr/local/lib -o app app.c -lutils -lhelpers
# Link with static library
c99 -o app app.c libmylib.a
# Link with shared library
c99 -o app app.c libmylib.so
# Explicit library specification
c99 -o app app.c /usr/local/lib/libspecial.a
Advanced Compilation
Optimization Levels
# No optimization (debug mode)
c99 -O0 -g program.c
# Basic optimization
c99 -O1 program.c
# Standard optimization (recommended)
c99 -O2 program.c
# Aggressive optimization
c99 -O3 program.c
# Size optimization
c99 -Os program.c
# Optimize for debugging
c99 -Og -g program.c
Architecture-Specific Compilation
# Compile for 32-bit architecture
c99 -W 32 program.c
# Compile for 64-bit architecture
c99 -W 64 program.c
# Cross-compilation examples
c99 -W 32 -o app32 program.c
c99 -W 64 -o app64 program.c
Development Workflow
Debug Build
# Development build with full debug info
c99 -g -DDEBUG -Wall -o debug_app program.c
# Debug with specific features
c99 -g -DDEBUG -DVERBOSE -O0 -o debug program.c
# Debug build with assertions
c99 -g -DDEBUG -DNDEBUG -o release_debug program.c
Release Build
# Optimized release build
c99 -O2 -DNDEBUG -s -o release_app program.c
# Production build with strip
c99 -O3 -DNDEBUG -s -o production program.c
# Release with custom optimization
c99 -O2 -march=native -DNDEBUG -o optimized program.c
Practical Examples
System Programming
POSIX Application Development
# POSIX-compliant application
c99 -D_POSIX_C_SOURCE=200112L -o posix_app posix_program.c
# Network programming with sockets
c99 -o network_server server.c -lsocket -lnsl
# Multi-threaded application
c99 -pthread -o threaded_app threads.c
# Signal handling application
c99 -D_POSIX_C_SOURCE=199309L -o signal_app signals.c
System Tools Development
# System utility development
c99 -D_XOPEN_SOURCE=600 -o sysutil system_utility.c
# File system tools
c99 -o fs_tool filesystem_tool.c
# Process management tool
c99 -o proc_monitor process_monitor.c -lpthread
Scientific Computing
Mathematical Applications
# Scientific computing application
c99 -O3 -march=native -o scientific scientific.c -lm
# Numerical analysis program
c99 -O2 -ffast-math -o numerical numerical.c -lm
# Data processing application
c99 -O3 -o data_processor data_processing.c -lm -lpthread
# Simulation program
c99 -O3 -fopenmp -o simulation simulation.c -lm
Performance-Critical Applications
# High-performance computing
c99 -O3 -march=native -ftree-vectorize -o hpc_app hpc.c
# Optimized mathematical library
c99 -O3 -ffast-math -o mathlib math_library.c -lm
# Real-time processing
c99 -O2 -DREALTIME -o realtime realtime_processor.c
Software Development
Library Development
# Compile shared library
c99 -fPIC -c library.c
c99 -shared -o liblibrary.so library.o
# Compile static library
c99 -c library.c
ar rcs liblibrary.a library.o
# Development version with debugging
c99 -fPIC -g -DDEBUG -c library.c
c99 -shared -o liblibrary_debug.so library.o
# Profile-guided optimization
c99 -fprofile-generate -o program program.c
./program
c99 -fprofile-use -o program_optimized program.c
Build System Integration
# Makefile compatible compilation
c99 -c -I./include src/*.c
c99 -o app *.o -L./lib -lm
# Header-only library usage
c99 -I./external/include -o app app.c
# Dependency generation
c99 -M -MF dependencies.d src.c
Testing and Validation
Unit Testing Setup
# Test build with testing framework
c99 -DTESTING -I./test -o test_suite tests.c -lcheck
# Debug build for testing
c99 -g -DDEBUG -DTESTING -o test_debug test_program.c
# Memory debugging build
c99 -g -DDEBUG -o memcheck_test program.c
# Coverage build
c99 -fprofile-arcs -ftest-coverage -o coverage_test program.c
Validation Builds
# Strict standards compliance
c99 -pedantic -std=c99 -Wall -Wextra -o strict_app program.c
# Warning-as-errors build
c99 -Werror -Wall -o production program.c
# Static analysis build
c99 -Wall -Wextra -fanalyzer -o analyzed program.c
Advanced Usage
Build Optimization
Parallel Compilation
# Parallel build (with make)
make -j$(nproc) CC=c99
# Batch compilation
for file in *.c; do
c99 -c "$file"
done
c99 -o app *.o
Incremental Builds
# Compile only changed files
c99 -c -I./include new_file.c
c99 -o app *.o -L./lib -lm
# Dependency-aware compilation
c99 -MMD -MF deps.d -c source.c
Cross-Platform Development
Portable Code Compilation
# Platform detection
c99 -DPLATFORM_UNIX -o unix_app unix_program.c
# Feature detection
c99 -DHAVE_PTHREAD -o threaded_app threaded_program.c
# Conditional compilation
c99 -DENDIAN_BIG -o big_endian big_endian_program.c
Integration and Automation
Build Scripts
Automated Build Script
#!/bin/bash
# Automated C99 build script
CC="c99"
CFLAGS="-Wall -Wextra -std=c99"
LDFLAGS=""
SOURCES="src/*.c"
TARGET="myapp"
# Debug build
build_debug() {
echo "Building debug version..."
$CC -g -DDEBUG $CFLAGS -o "${TARGET}_debug" $SOURCES $LDFLAGS
}
# Release build
build_release() {
echo "Building release version..."
$CC -O2 -DNDEBUG $CFLAGS -s -o "$TARGET" $SOURCES $LDFLAGS
}
# Library build
build_library() {
echo "Building library..."
$CC -fPIC -c lib_source.c
$CC -shared -o libmylib.so lib_source.o
}
case "$1" in
debug)
build_debug
;;
release)
build_release
;;
library)
build_library
;;
*)
echo "Usage: $0 {debug|release|library}"
exit 1
;;
esac
Development Environment Setup
#!/bin/bash
# Development environment setup for C99
# Set environment variables
export CC="c99"
export CFLAGS="-Wall -Wextra -std=c99 -g"
export LDFLAGS="-lm"
# Create project structure
mkdir -p {src,include,lib,bin,tests}
# Compile with standard options
c99 $CFLAGS -I./include -o bin/app src/main.c src/utils.c $LDFLAGS
echo "Build completed successfully"
Make Integration
Makefile Template
CC = c99
CFLAGS = -Wall -Wextra -std=c99
LDFLAGS = -lm
SOURCES = $(wildcard src/*.c)
OBJECTS = $(SOURCES:.c=.o)
TARGET = myapp
.PHONY: all clean debug release
all: $(TARGET)
$(TARGET): $(OBJECTS)
$(CC) -o $@ $^ $(LDFLAGS)
%.o: %.c
$(CC) $(CFLAGS) -c $< -o $@
debug: CFLAGS += -g -DDEBUG
debug: $(TARGET)
release: CFLAGS += -O2 -DNDEBUG -s
release: $(TARGET)
clean:
rm -f $(OBJECTS) $(TARGET)
Troubleshooting
Common Issues
Header File Not Found
# Problem: Header file not in search path
# Solution: Add include directory
c99 -I./include -o program program.c
# Multiple include directories
c99 -I./include -I/usr/local/include -o program program.c
Library Not Found
# Problem: Library not found during linking
# Solution: Add library directory
c99 -L./lib -o program program.c -lmylib
# Check library existence
ls -la /usr/local/lib/libmylib.*
Macro Conflicts
# Problem: Macro definition conflicts
# Solution: Undefine conflicting macros
c99 -Umacro_name -Dmacro_name=new_value program.c
# Priority: -U overrides -D
c99 -UDEBUG -DDEBUG=1 program.c
Architecture Mismatch
# Problem: Architecture mismatch
# Solution: Specify correct architecture
c99 -W 64 -o program64 program.c
c99 -W 32 -o program32 program.c
Build Errors
Compilation Errors
# Verbose error output
c99 -v -o program program.c
# Stop after preprocessing to check macros
c99 -E -dM program.c
# Generate preprocessed output for debugging
c99 -E program.c > preprocessed.c
Linking Errors
# Show library search order
c99 -Wl,--verbose -o program program.c -lm
# Check library symbols
nm -C libmylib.a | grep symbol_name
# Undefined symbol debugging
c99 -Wl,--no-undefined -o program program.c
Related Commands
gcc- GNU C Compilerclang- Clang C Compilerc89- C89 Compilermake- Build automation toolar- Archive utility for creating static librariesld- GNU linkerobjdump- Object file information utilitynm- Symbol listing utilitystrip- Strip symbols from object files
Best Practices
- Always use C99 standard for portable code development
- Define feature test macros for POSIX compliance (
_POSIX_C_SOURCE) - Use appropriate optimization levels based on build type (debug vs. release)
- Include debugging information (-g) for development builds
- Strip executables (-s) for production releases
- Specify include paths explicitly for better dependency management
- Use library search paths (-L) for custom libraries
- Enable all warnings (-Wall -Wextra) for robust code
- Test with different architectures using -W option for portability
- Document build requirements in build scripts and documentation
Performance Tips
- Use -O2 for balanced optimization in most cases
- Consider -O3 for computation-intensive applications
- Use -Os for size-critical applications
- Enable -march=native for platform-specific optimizations
- Profile-guided optimization for critical applications
- Link-time optimization can improve performance
- Avoid -O0 in production builds
- Use appropriate pointer size (-W) for target architecture
- Consider parallel compilation for large projects
- Profile before optimizing to identify bottlenecks
The c99 command provides a standardized, POSIX-compliant interface for C compilation that ensures consistent behavior across different UNIX-like systems. Its strict adherence to the C99 standard makes it ideal for portable C development, while its integration with the underlying C compiler provides access to advanced optimization and debugging features.