forked from aaronbloomfield/pdr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcompiler_flags.html
28 lines (28 loc) · 3.16 KB
/
compiler_flags.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="Content-Style-Type" content="text/css" />
<meta name="generator" content="pandoc" />
<title>PDR: Docs: Useful Compiler Flags</title>
<style type="text/css">code{white-space: pre;}</style>
<link rel="stylesheet" href="../markdown.css" type="text/css" />
</head>
<body>
<h1 id="pdr-docs-useful-compiler-flags">PDR: Docs: Useful Compiler Flags</h1>
<p><a href="index.html">Go up to the main documents page</a> (<a href="index.md">md</a>)</p>
<p>This page is intended to summarize the various compiler flags that we will be learning throughout the semester. There are hundreds (if not thousands!) of such options; we'll only be dealing with a few of them.</p>
<p>These flags are for the clang compiler, but the are mostly the same for the g++ compiler (the only difference, of the ones listed below, are the flags to generate the particualr assembly flavor).</p>
<ul>
<li><code>-O2</code>: Creates an optimized executable. Note that if you are using the -c command (below), then you should call -O2 for those as well as the final linker call.</li>
<li><code>-c <filename.cpp></code>: This flag will compile BUT NOT LINK the passed .cpp file. It will create a filename.o file. To create the executable, you must call the compiler with all the .o files (i.e. <code>clang *.o</code>)</li>
<li><code>-o <filename></code>: This will save the output executable into <filename>.exe (or, in Linux/Unix, just <filename>). For example, <code>clang -o foo foo.cpp</code> will compile the foo.cpp file and name the executable 'foo'. If you do out specify this flag, the output is saved to a.exe (or a.out in Linux/Unix). The 'o' in <code>-o</code> stands for output (as in output file).</li>
<li><code>-g</code>: Include debugging information in the executable file. This is needed to debug the file in gdb.</li>
<li><code>-Wall</code>: Display all warning messages. An error will prevent the program from being compiled, whereas a warning will not. There are many types of warnings that can be displayed, some of which are rather obscure. The 'all' part means to display all of them. It is a good idea to use this, as warnings are often bugs in your program.</li>
<li><code>-S</code>: generate assembly output, and then stop (i.e. does not compile the program beyond the x86 assembly). Note that the assembly format that is created as a result of this flag has a different format than what we have seen in lecture -- the idea is the same, but the register specification is different, and the destination/source order is reversed for the commands.</li>
<li><code>-mllvm --x86-asm-syntax=intel</code>: sets the assembly output format to the flavor that we are used to in (this is the only flag on this list that is not the same in g++)</li>
<li><code>-MM</code>: generates dependencies in the format used in Makefiles</li>
</ul>
<p>If you want to see all of the clang options, enter <code>man clang</code> at the Linux prompt. It's quite a list!</p>
</body>
</html>