cpp command in Linux with Examples Last Updated : 15 May, 2019 Comments Improve Suggest changes 1 Likes Like Report cpp is the C language preprocessor, it is automatically used by your C compiler to transform your program before compilation. It is also termed as a macro processor because it is used to give abbreviations for the longer piece of code. It can only be used with C, C++ and Objective-C source code. Using with other programming languages may cause uncertain problems. Syntax: cpp [-options] infile outfile Some Important Options: -D name : Predefine name as a macro. -D name=definition : The contents of definition are tokenized and processed as if they are written in program itself. -U name : Cancel any previous definition of macro. -undef : Do not predefine any system-specific or GCC-specific macros. The standard predefined macros remain defined. -I dir : Add the directory dir to the list of directories to be searched for header files. -Wall : Turns on all optional warnings which are desirable for normal code. -Wcomments : Warn whenever a comment-start sequence /* appears in a /* comment, or whenever a backslash-newline appears in a // comment. -Wendif-labels : Warn whenever an #else or an #endif are followed by text. -w : Suppress all warnings, including those which GNU CPP issues by default. -M : Instead of outputting the result of preprocessing, output a rule suitable for make describing the dependencies of the main source file. -MM : Like -M but do not mention header files that are found in system header directories. -x c -x c++ -x objective-c -x assembler-with-cpp : All four above Specify the source language: C, C++, Objective-C, or assembly. This has nothing to do with standards conformance or extensions; it merely selects which base syntax to expect. Examples: We have created two codes to explain the concept we will refer them as code_a.c and code_b.c. #include void main() { printf("Hello, World!"); } code_a.c #include void main() { printf(out); } code_b.c Using cpp command : It will result into the following output: # 1 "code_a.c" # 1 "" # 1 "" # 1 "/usr/include/stdc-predef.h" 1 3 4 # 1 "" 2 # 1 "code_a.c" # 1 "/usr/include/stdio.h" 1 3 4 # 27 "/usr/include/stdio.h" 3 4 # 1 "/usr/include/features.h" 1 3 4 # 367 "/usr/include/features.h" 3 4 # 1 "/usr/include/x86_64-linux-gnu/sys/cdefs.h" 1 3 4 # 410 "/usr/include/x86_64-linux-gnu/sys/cdefs.h" 3 4 # 1 "/usr/include/x86_64-linux-gnu/bits/wordsize.h" 1 3 4 # 411 "/usr/include/x86_64-linux-gnu/sys/cdefs.h" 2 3 4 # 368 "/usr/include/features.h" 2 3 4 # 391 "/usr/include/features.h" 3 4 .......... ............. .................... # 2 "code_a.c" void main() { printf("Hello, World!"); } The output is too large and we actually don't need it to understand the concept. The thing we understood is that it simply called and replaced the whole piece of code in the header files to the program. using -D option : # 1 "code_b.c" # 1 "" # 1 "" # 1 "/usr/include/stdc-predef.h" 1 3 4 # 1 "" 2 # 1 "code_a.c" # 1 "/usr/include/stdio.h" 1 3 4 # 27 "/usr/include/stdio.h" 3 4 # 1 "/usr/include/features.h" 1 3 4 # 367 "/usr/include/features.h" 3 4 # 1 "/usr/include/x86_64-linux-gnu/sys/cdefs.h" 1 3 4 # 410 "/usr/include/x86_64-linux-gnu/sys/cdefs.h" 3 4 # 1 "/usr/include/x86_64-linux-gnu/bits/wordsize.h" 1 3 4 # 411 "/usr/include/x86_64-linux-gnu/sys/cdefs.h" 2 3 4 # 368 "/usr/include/features.h" 2 3 4 # 391 "/usr/include/features.h" 3 4 .......... ............. .................... # 2 "code_b.c" void main() { printf("Hello, World!"); } Observe that it prints the same result. This is because it used the macro we declared on the command line. Using -M option: Observed the difference. This is because it only outputs the rules required for make. Create Quiz Comment V VivekAgrawal3 Follow 1 Improve V VivekAgrawal3 Follow 1 Improve Article Tags : Linux-Unix Explore Linux/Unix Tutorial 5 min read Getting Started with LinuxWhat is Linux Operating System 8 min read LINUX Full Form - Lovable Intellect Not Using XP 2 min read Difference between Linux and Windows 7 min read What are Linux Distributions ? 8 min read Difference between Unix and Linux 5 min read Installation with LinuxHow to Install Arch Linux in VirtualBox? 7 min read Fedora Linux Operating System 12 min read How to install Ubuntu on VirtualBox? 6 min read How to Install Linux Mint? 3 min read How to Install Kali Linux on Windows? 2 min read How to Install Linux on Windows PowerShell Subsystem? 2 min read How to Find openSUSE Linux Version? 2 min read How to Install CentOS 2 min read Linux CommandsLinux Commands 15+ min read Essential Unix Commands 7 min read Find Command in Linux with Examples 7 min read Linux File SystemLinux File System 12 min read Linux File Hierarchy Structure 5 min read Linux Directory Structure 6 min read Linux KernelLinux Kernel 4 min read Kernel in Operating System 3 min read How Linux Kernel Boots? 11 min read Difference between Operating System and Kernel 3 min read Linux Kernel Module Programming: Hello World Program 7 min read Linux Loadable Kernel Module 7 min read Loadable Kernel Module - Linux Device Driver Development 4 min read Linux Networking ToolsNetwork configuration and troubleshooting commands in Linux 5 min read How to configure network interfaces in CentOS? 5 min read Command-Line Tools and Utilities For Network Management in Linux 8 min read Linux - Network Monitoring Tools 4 min read Linux ProcessProcesses in Linux/Unix 5 min read How to Manage Process in Linux 4 min read Getting System and Process Information Using C Programming and Shell in Linux 2 min read Process states and Transitions in a UNIX Process 4 min read Linux FirewallLINUX Firewall 7 min read iptables command in Linux with Examples 7 min read How to Configure your Linux Firewall - 3 Methods 12 min read Shell Scripting & Bash ScriptingIntroduction to Linux Shell and Shell Scripting 7 min read What is Terminal, Console, Shell and Kernel? 5 min read How to Create a Shell Script in linux 7 min read Shell Scripting - Different types of Variables 4 min read Bash Scripting - Introduction to Bash and Bash Scripting 12 min read Bash Script - Define Bash Variables and its types 12 min read Shell Scripting - Shell Variables 6 min read Bash Script - Difference between Bash Script and Shell Script 4 min read Shell Scripting - Difference between Korn Shell and Bash shell 3 min read Shell Scripting - Interactive and Non-Interactive Shell 3 min read Shell Script to Show the Difference Between echo â$SHELLâ and echo â$SHELLâ 4 min read Like