-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathcompiling-and-building.html
More file actions
247 lines (199 loc) · 94.6 KB
/
compiling-and-building.html
File metadata and controls
247 lines (199 loc) · 94.6 KB
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
<!DOCTYPE html>
<html lang="en-US">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<title>C++ | Compiling and Building</title>
<meta name="generator" content="VuePress 1.8.2">
<link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png">
<link rel="manifest" href="/site.webmanifest">
<link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png">
<link rel="mask-icon" href="/safari-pinned-tab.svg" color="#5bbad5">
<meta name="description" content="Compiling with GCC, Compiling with Visual Studio (Graphical Interface) - Hello World, Online Compilers, Compiling with Visual C++ (Command Line), Compiling with Clang, The C++ compilation process, Compiling with Code::Blocks (Graphical interface)">
<meta property="og:site_name" content="DevTut">
<meta property="og:title" content="C++ | Compiling and Building">
<meta property="og:description" content="Compiling with GCC, Compiling with Visual Studio (Graphical Interface) - Hello World, Online Compilers, Compiling with Visual C++ (Command Line), Compiling with Clang, The C++ compilation process, Compiling with Code::Blocks (Graphical interface)">
<meta property="og:type" content="article">
<meta property="og:url" content="/cpp/compiling-and-building.html">
<meta property="og:image" content="/logo.png">
<meta name="twitter:title" content="C++ | Compiling and Building">
<meta name="twitter:description" content="Compiling with GCC, Compiling with Visual Studio (Graphical Interface) - Hello World, Online Compilers, Compiling with Visual C++ (Command Line), Compiling with Clang, The C++ compilation process, Compiling with Code::Blocks (Graphical interface)">
<meta name="twitter:url" content="/cpp/compiling-and-building.html">
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:image" content="/logo.png">
<meta name="theme-color" content="#ffffff">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<meta name="msapplication-TileImage" content="/mstile-150x150.png">
<meta name="msapplication-TileColor" content="#da532c">
<meta name="google-site-verification" content="76_rKXgwMVIjd-axJC_1zPV9OS4mEjvtgjYOWVkAdnQ">
<link rel="preload" href="/assets/css/0.styles.60619e34.css" as="style"><link rel="preload" href="/assets/js/app.1779e102.js" as="script"><link rel="preload" href="/assets/js/3.2cfa8016.js" as="script"><link rel="preload" href="/assets/js/632.7ab15d44.js" as="script">
<link rel="stylesheet" href="/assets/css/0.styles.60619e34.css">
</head>
<body>
<div id="app" data-server-rendered="true"><div class="theme-container"><header class="navbar"><div class="sidebar-button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" role="img" viewBox="0 0 448 512" class="icon"><path fill="currentColor" d="M436 124H12c-6.627 0-12-5.373-12-12V80c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12z"></path></svg></div> <a href="/" class="home-link router-link-active"><!----> <span class="site-name">DevTut</span></a> <div class="links"><form id="search-form" role="search" class="algolia-search-wrapper search-box"><input id="algolia-search-input" class="search-query"></form> <nav class="nav-links can-hide"> <a href="https://github.com/devtut/generate" target="_blank" rel="noopener noreferrer" class="repo-link">
GitHub
<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></nav></div></header> <div class="sidebar-mask"></div> <aside class="sidebar"><nav class="nav-links"> <a href="https://github.com/devtut/generate" target="_blank" rel="noopener noreferrer" class="repo-link">
GitHub
<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></nav> <ul class="sidebar-links"><li><section class="sidebar-group depth-0"><p class="sidebar-heading open"><span>C++</span> <!----></p> <ul class="sidebar-links sidebar-group-items"><li><a href="/cpp/" aria-current="page" class="sidebar-link">Disclaimer</a></li><li><a href="/cpp/getting-started-with-cpp.html" class="sidebar-link">Getting started with C++</a></li><li><a href="/cpp/literals.html" class="sidebar-link">Literals</a></li><li><a href="/cpp/operator-precedence.html" class="sidebar-link">operator precedence</a></li><li><a href="/cpp/floating-point-arithmetic.html" class="sidebar-link">Floating Point Arithmetic</a></li><li><a href="/cpp/bit-operators.html" class="sidebar-link">Bit Operators</a></li><li><a href="/cpp/bit-manipulation.html" class="sidebar-link">Bit Manipulation</a></li><li><a href="/cpp/bit-fields.html" class="sidebar-link">Bit fields</a></li><li><a href="/cpp/arrays.html" class="sidebar-link">Arrays</a></li><li><a href="/cpp/iterators.html" class="sidebar-link">Iterators</a></li><li><a href="/cpp/basic-input-output-in-c.html" class="sidebar-link">Basic input/output in c++</a></li><li><a href="/cpp/loops.html" class="sidebar-link">Loops</a></li><li><a href="/cpp/file-i-o.html" class="sidebar-link">File I/O</a></li><li><a href="/cpp/cpp-streams.html" class="sidebar-link">C++ Streams</a></li><li><a href="/cpp/stream-manipulators.html" class="sidebar-link">Stream manipulators</a></li><li><a href="/cpp/flow-control.html" class="sidebar-link">Flow Control</a></li><li><a href="/cpp/metaprogramming.html" class="sidebar-link">Metaprogramming</a></li><li><a href="/cpp/const-keyword.html" class="sidebar-link">const keyword</a></li><li><a href="/cpp/mutable-keyword.html" class="sidebar-link">mutable keyword</a></li><li><a href="/cpp/friend-keyword.html" class="sidebar-link">Friend keyword</a></li><li><a href="/cpp/type-keywords.html" class="sidebar-link">Type Keywords</a></li><li><a href="/cpp/basic-type-keywords.html" class="sidebar-link">Basic Type Keywords</a></li><li><a href="/cpp/variable-declaration-keywords.html" class="sidebar-link">Variable Declaration Keywords</a></li><li><a href="/cpp/keywords.html" class="sidebar-link">Keywords</a></li><li><a href="/cpp/returning-several-values-from-a-function.html" class="sidebar-link">Returning several values from a function</a></li><li><a href="/cpp/polymorphism.html" class="sidebar-link">Polymorphism</a></li><li><a href="/cpp/references.html" class="sidebar-link">References</a></li><li><a href="/cpp/value-and-reference-semantics.html" class="sidebar-link">Value and Reference Semantics</a></li><li><a href="/cpp/c-function-call-by-value-vs-call-by-reference.html" class="sidebar-link">C++ function "call by value" vs. "call by reference"</a></li><li><a href="/cpp/copying-vs-assignment.html" class="sidebar-link">Copying vs Assignment</a></li><li><a href="/cpp/pointers.html" class="sidebar-link">Pointers</a></li><li><a href="/cpp/pointers-to-members.html" class="sidebar-link">Pointers to members</a></li><li><a href="/cpp/the-this-pointer.html" class="sidebar-link">The This Pointer</a></li><li><a href="/cpp/smart-pointers.html" class="sidebar-link">Smart Pointers</a></li><li><a href="/cpp/classes-structures.html" class="sidebar-link">Classes/Structures</a></li><li><a href="/cpp/function-overloading.html" class="sidebar-link">Function Overloading</a></li><li><a href="/cpp/operator-overloading.html" class="sidebar-link">Operator Overloading</a></li><li><a href="/cpp/function-template-overloading.html" class="sidebar-link">Function Template Overloading</a></li><li><a href="/cpp/virtual-member-functions.html" class="sidebar-link">Virtual Member Functions</a></li><li><a href="/cpp/inline-functions.html" class="sidebar-link">Inline functions</a></li><li><a href="/cpp/special-member-functions.html" class="sidebar-link">Special Member Functions</a></li><li><a href="/cpp/non-static-member-functions.html" class="sidebar-link">Non-Static Member Functions</a></li><li><a href="/cpp/constant-class-member-functions.html" class="sidebar-link">Constant class member functions</a></li><li><a href="/cpp/c-containers.html" class="sidebar-link">C++ Containers</a></li><li><a href="/cpp/namespaces.html" class="sidebar-link">Namespaces</a></li><li><a href="/cpp/header-files.html" class="sidebar-link">Header Files</a></li><li><a href="/cpp/using-declaration.html" class="sidebar-link">Using declaration</a></li><li><a href="/cpp/std-string.html" class="sidebar-link">std::string</a></li><li><a href="/cpp/std-array.html" class="sidebar-link">std::array</a></li><li><a href="/cpp/std-vector.html" class="sidebar-link">std::vector</a></li><li><a href="/cpp/std-map.html" class="sidebar-link">std::map</a></li><li><a href="/cpp/std-optional.html" class="sidebar-link">std::optional</a></li><li><a href="/cpp/std-function-to-wrap-any-element-that-is-callable.html" class="sidebar-link">std::function: To wrap any element that is callable</a></li><li><a href="/cpp/std-forward-list.html" class="sidebar-link">std::forward_list</a></li><li><a href="/cpp/std-pair.html" class="sidebar-link">std::pair</a></li><li><a href="/cpp/std-atomics.html" class="sidebar-link">std::atomics</a></li><li><a href="/cpp/std-variant.html" class="sidebar-link">std::variant</a></li><li><a href="/cpp/std-iomanip.html" class="sidebar-link">std::iomanip</a></li><li><a href="/cpp/std-any.html" class="sidebar-link">std::any</a></li><li><a href="/cpp/std-set-and-std-multiset.html" class="sidebar-link">std::set and std::multiset</a></li><li><a href="/cpp/std-integer-sequence.html" class="sidebar-link">std::integer_sequence</a></li><li><a href="/cpp/using-std-unordered-map.html" class="sidebar-link">Using std::unordered_map</a></li><li><a href="/cpp/standard-library-algorithms.html" class="sidebar-link">Standard Library Algorithms</a></li><li><a href="/cpp/the-iso-c-standard.html" class="sidebar-link">The ISO C++ Standard</a></li><li><a href="/cpp/inline-variables.html" class="sidebar-link">Inline variables</a></li><li><a href="/cpp/random-number-generation.html" class="sidebar-link">Random number generation</a></li><li><a href="/cpp/date-and-time-using-chrono-header.html" class="sidebar-link">Date and time using header</a></li><li><a href="/cpp/sorting.html" class="sidebar-link">Sorting</a></li><li><a href="/cpp/enumeration.html" class="sidebar-link">Enumeration</a></li><li><a href="/cpp/iteration.html" class="sidebar-link">Iteration</a></li><li><a href="/cpp/regular-expressions.html" class="sidebar-link">Regular expressions</a></li><li><a href="/cpp/implementation-defined-behavior.html" class="sidebar-link">Implementation-defined behavior</a></li><li><a href="/cpp/exceptions.html" class="sidebar-link">Exceptions</a></li><li><a href="/cpp/lambdas.html" class="sidebar-link">Lambdas</a></li><li><a href="/cpp/value-categories.html" class="sidebar-link">Value Categories</a></li><li><a href="/cpp/preprocessor.html" class="sidebar-link">Preprocessor</a></li><li><a href="/cpp/data-structures-in-c.html" class="sidebar-link">Data Structures in C++</a></li><li><a href="/cpp/templates.html" class="sidebar-link">Templates</a></li><li><a href="/cpp/expression-templates.html" class="sidebar-link">Expression templates</a></li><li><a href="/cpp/curiously-recurring-template-pattern-crtp.html" class="sidebar-link">Curiously Recurring Template Pattern (CRTP)</a></li><li><a href="/cpp/threading.html" class="sidebar-link">Threading</a></li><li><a href="/cpp/thread-synchronization-structures.html" class="sidebar-link">Thread synchronization structures</a></li><li><a href="/cpp/the-rule-of-three-five-and-zero.html" class="sidebar-link">The Rule of Three, Five, And Zero</a></li><li><a href="/cpp/raii-resource-acquisition-is-initialization.html" class="sidebar-link">RAII: Resource Acquisition Is Initialization</a></li><li><a href="/cpp/rtti-run-time-type-information.html" class="sidebar-link">RTTI: Run-Time Type Information</a></li><li><a href="/cpp/mutexes.html" class="sidebar-link">Mutexes</a></li><li><a href="/cpp/recursive-mutex.html" class="sidebar-link">Recursive Mutex</a></li><li><a href="/cpp/semaphore.html" class="sidebar-link">Semaphore</a></li><li><a href="/cpp/futures-and-promises.html" class="sidebar-link">Futures and Promises</a></li><li><a href="/cpp/atomic-types.html" class="sidebar-link">Atomic Types</a></li><li><a href="/cpp/type-erasure.html" class="sidebar-link">Type Erasure</a></li><li><a href="/cpp/explicit-type-conversions.html" class="sidebar-link">Explicit type conversions</a></li><li><a href="/cpp/unnamed-types.html" class="sidebar-link">Unnamed types</a></li><li><a href="/cpp/type-traits.html" class="sidebar-link">Type Traits</a></li><li><a href="/cpp/return-type-covariance.html" class="sidebar-link">Return Type Covariance</a></li><li><a href="/cpp/layout-of-object-types.html" class="sidebar-link">Layout of object types</a></li><li><a href="/cpp/type-inference.html" class="sidebar-link">Type Inference</a></li><li><a href="/cpp/typedef-and-type-aliases.html" class="sidebar-link">Typedef and type aliases</a></li><li><a href="/cpp/type-deduction.html" class="sidebar-link">type deduction</a></li><li><a href="/cpp/trailing-return-type.html" class="sidebar-link">Trailing return type</a></li><li><a href="/cpp/alignment.html" class="sidebar-link">Alignment</a></li><li><a href="/cpp/perfect-forwarding.html" class="sidebar-link">Perfect Forwarding</a></li><li><a href="/cpp/decltype.html" class="sidebar-link">decltype</a></li><li><a href="/cpp/sfinae-substitution-failure-is-not-an-error.html" class="sidebar-link">SFINAE (Substitution Failure Is Not An Error)</a></li><li><a href="/cpp/undefined-behavior.html" class="sidebar-link">Undefined Behavior</a></li><li><a href="/cpp/overload-resolution.html" class="sidebar-link">Overload resolution</a></li><li><a href="/cpp/move-semantics.html" class="sidebar-link">Move Semantics</a></li><li><a href="/cpp/pimpl-idiom.html" class="sidebar-link">Pimpl Idiom</a></li><li><a href="/cpp/auto.html" class="sidebar-link">auto</a></li><li><a href="/cpp/copy-elision.html" class="sidebar-link">Copy Elision</a></li><li><a href="/cpp/fold-expressions.html" class="sidebar-link">Fold Expressions</a></li><li><a href="/cpp/unions.html" class="sidebar-link">Unions</a></li><li><a href="/cpp/design-pattern-implementation-in-c.html" class="sidebar-link">Design pattern implementation in C++</a></li><li><a href="/cpp/singleton-design-pattern.html" class="sidebar-link">Singleton Design Pattern</a></li><li><a href="/cpp/user-defined-literals.html" class="sidebar-link">User-Defined Literals</a></li><li><a href="/cpp/memory-management.html" class="sidebar-link">Memory management</a></li><li><a href="/cpp/c-11-memory-model.html" class="sidebar-link">C++11 Memory Model</a></li><li><a href="/cpp/scopes.html" class="sidebar-link">Scopes</a></li><li><a href="/cpp/static-assert.html" class="sidebar-link">static_assert</a></li><li><a href="/cpp/constexpr.html" class="sidebar-link">constexpr</a></li><li><a href="/cpp/one-definition-rule-odr.html" class="sidebar-link">One Definition Rule (ODR)</a></li><li><a href="/cpp/unspecified-behavior.html" class="sidebar-link">Unspecified behavior</a></li><li><a href="/cpp/argument-dependent-name-lookup.html" class="sidebar-link">Argument Dependent Name Lookup</a></li><li><a href="/cpp/attributes.html" class="sidebar-link">Attributes</a></li><li><a href="/cpp/recursion-in-c.html" class="sidebar-link">Recursion in C++</a></li><li><a href="/cpp/arithmitic-metaprogramming.html" class="sidebar-link">Arithmitic Metaprogramming</a></li><li><a href="/cpp/callable-objects.html" class="sidebar-link">Callable Objects</a></li><li><a href="/cpp/client-server-examples.html" class="sidebar-link">Client server examples</a></li><li><a href="/cpp/const-correctness.html" class="sidebar-link">Const Correctness</a></li><li><a href="/cpp/parameter-packs.html" class="sidebar-link">Parameter packs</a></li><li><a href="/cpp/build-systems.html" class="sidebar-link">Build Systems</a></li><li><a href="/cpp/concurrency-with-openmp.html" class="sidebar-link">Concurrency With OpenMP</a></li><li><a href="/cpp/resource-management.html" class="sidebar-link">Resource Management</a></li><li><a href="/cpp/storage-class-specifiers.html" class="sidebar-link">Storage class specifiers</a></li><li><a href="/cpp/linkage-specifications.html" class="sidebar-link">Linkage specifications</a></li><li><a href="/cpp/digit-separators.html" class="sidebar-link">Digit separators</a></li><li><a href="/cpp/c-incompatibilities.html" class="sidebar-link">C incompatibilities</a></li><li><a href="/cpp/side-by-side-comparisons-of-classic-c-examples-solved-via-c-vs-c-11-vs-c-14-vs-c-17.html" class="sidebar-link">Side by Side Comparisons of classic C++ examples solved via C++ vs C++11 vs C++14 vs C++17</a></li><li><a href="/cpp/compiling-and-building.html" aria-current="page" class="active sidebar-link">Compiling and Building</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/cpp/compiling-and-building.html#compiling-with-gcc" class="sidebar-link">Compiling with GCC</a></li><li class="sidebar-sub-header"><a href="/cpp/compiling-and-building.html#compiling-with-visual-studio-graphical-interface-hello-world" class="sidebar-link">Compiling with Visual Studio (Graphical Interface) - Hello World</a></li><li class="sidebar-sub-header"><a href="/cpp/compiling-and-building.html#online-compilers" class="sidebar-link">Online Compilers</a></li><li class="sidebar-sub-header"><a href="/cpp/compiling-and-building.html#compiling-with-visual-c-command-line" class="sidebar-link">Compiling with Visual C++ (Command Line)</a></li><li class="sidebar-sub-header"><a href="/cpp/compiling-and-building.html#compiling-with-clang" class="sidebar-link">Compiling with Clang</a></li><li class="sidebar-sub-header"><a href="/cpp/compiling-and-building.html#the-c-compilation-process" class="sidebar-link">The C++ compilation process</a></li><li class="sidebar-sub-header"><a href="/cpp/compiling-and-building.html#compiling-with-code-blocks-graphical-interface" class="sidebar-link">Compiling with Code::Blocks (Graphical interface)</a></li></ul></li><li><a href="/cpp/common-compile-linker-errors-gcc.html" class="sidebar-link">Common compile/linker errors (GCC)</a></li><li><a href="/cpp/more-undefined-behaviors-in-c.html" class="sidebar-link">More undefined behaviors in C++</a></li><li><a href="/cpp/unit-testing-in-c.html" class="sidebar-link">Unit Testing in C++</a></li><li><a href="/cpp/c-debugging-and-debug-prevention-tools-techniques.html" class="sidebar-link">C++ Debugging and Debug-prevention Tools & Techniques</a></li><li><a href="/cpp/optimization-in-c.html" class="sidebar-link">Optimization in C++</a></li><li><a href="/cpp/optimization.html" class="sidebar-link">Optimization</a></li><li><a href="/cpp/profiling.html" class="sidebar-link">Profiling</a></li><li><a href="/cpp/refactoring-techniques.html" class="sidebar-link">Refactoring Techniques</a></li><li><a href="/cpp/internationalization-in-c.html" class="sidebar-link">Internationalization in C++</a></li><li><a href="/cpp/contributors.html" class="sidebar-link">The Contributors</a></li></ul></section></li></ul> </aside> <main class="page"> <div class="theme-default-content content__default"><h1 id="compiling-and-building"><a href="#compiling-and-building" class="header-anchor">#</a> Compiling and Building</h1> <p>Programs written in C++ need to be compiled before they can be run. There is a large variety of compilers available depending on your operating system.</p> <h2 id="compiling-with-gcc"><a href="#compiling-with-gcc" class="header-anchor">#</a> Compiling with GCC</h2> <p>Assuming a single source file named <code>main.cpp</code>, the command to compile and link an non-optimized executable is as follows (Compiling without optimization is useful for initial development and debugging, although <a href="https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html#index-Og-723" target="_blank" rel="noopener noreferrer"><code>-Og</code><span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a> is officially recommended for newer GCC versions).</p> <div class="language-cpp extra-class"><pre class="language-cpp"><code>g<span class="token operator">++</span> <span class="token operator">-</span>o app <span class="token operator">-</span>Wall main<span class="token punctuation">.</span>cpp <span class="token operator">-</span>O0
</code></pre></div><p>To produce an optimized executable for use in production, use one of the <a href="https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html#index-O-716" target="_blank" rel="noopener noreferrer"><code>-O</code><span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a> options (see: <a href="https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html#index-O1-717" target="_blank" rel="noopener noreferrer"><code>-O1</code><span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a>, <a href="https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html#index-O2-718" target="_blank" rel="noopener noreferrer"><code>-O2</code><span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a>, <a href="https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html#index-O3-719" target="_blank" rel="noopener noreferrer"><code>-O3</code><span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a>, <a href="https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html#index-Os-721" target="_blank" rel="noopener noreferrer"><code>-Os</code><span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a>, <a href="https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html#index-Ofast-722" target="_blank" rel="noopener noreferrer"><code>-Ofast</code><span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a>):</p> <div class="language-cpp extra-class"><pre class="language-cpp"><code>g<span class="token operator">++</span> <span class="token operator">-</span>o app <span class="token operator">-</span>Wall <span class="token operator">-</span>O2 main<span class="token punctuation">.</span>cpp
</code></pre></div><p>If the -O option is omitted, -O0, which means no optimizations, is used as default (specifying -O without a number resolves to -O1).</p> <p>Alternatively, use optimization flags from the <code>O</code> groups (or more experimental optimizations) directly. The following example builds with <code>-O2</code> optimization, plus one flag from the <code>-O3</code> optimization level:</p> <div class="language-cpp extra-class"><pre class="language-cpp"><code>g<span class="token operator">++</span> <span class="token operator">-</span>o app <span class="token operator">-</span>Wall <span class="token operator">-</span>O2 <span class="token operator">-</span>ftree<span class="token operator">-</span>partial<span class="token operator">-</span>pre main<span class="token punctuation">.</span>cpp
</code></pre></div><p>To produce a platform-specific optimized executable (for use in production on the machine with the same architecture), use:</p> <div class="language-cpp extra-class"><pre class="language-cpp"><code>g<span class="token operator">++</span> <span class="token operator">-</span>o app <span class="token operator">-</span>Wall <span class="token operator">-</span>O2 <span class="token operator">-</span>march<span class="token operator">=</span>native main<span class="token punctuation">.</span>cpp
</code></pre></div><p>Either of the above will produce a binary file that can be run with <code>.\app.exe</code> on Windows and <code>./app</code> on Linux, Mac OS, etc.</p> <p>The <a href="https://gcc.gnu.org/onlinedocs/gcc/Overall-Options.html#index-o-86" target="_blank" rel="noopener noreferrer"><code>-o</code><span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a> flag can also be skipped. In this case, GCC will create default output executable <code>a.exe</code> on Windows and <code>a.out</code> on Unix-like systems.
To compile a file without linking it, use the <a href="https://gcc.gnu.org/onlinedocs/gcc/Overall-Options.html#index-c-82" target="_blank" rel="noopener noreferrer"><code>-c</code><span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a> option:</p> <div class="language-cpp extra-class"><pre class="language-cpp"><code>g<span class="token operator">++</span> <span class="token operator">-</span>o file<span class="token punctuation">.</span>o <span class="token operator">-</span>Wall <span class="token operator">-</span>c file<span class="token punctuation">.</span>cpp
</code></pre></div><p>This produces an object file named <code>file.o</code> which can later be linked with other files to produce a binary:</p> <div class="language-cpp extra-class"><pre class="language-cpp"><code>g<span class="token operator">++</span> <span class="token operator">-</span>o app file<span class="token punctuation">.</span>o otherfile<span class="token punctuation">.</span>o
</code></pre></div><p>More about optimization options can be found at <a href="https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html" target="_blank" rel="noopener noreferrer">gcc.gnu.org<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a>. Of particular note are <code>-Og</code> (optimization with an emphasis on debugging experience -- recommended for the standard edit-compile-debug cycle) and <code>-Ofast</code> (all optimizations, including ones disregarding strict standards compliance).</p> <p>The <a href="https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html#index-Wall-307" target="_blank" rel="noopener noreferrer"><code>-Wall</code><span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a> flag enables warnings for many common errors and should always be used. To improve code quality it is often encouraged also to use <a href="https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html#index-Wextra-310" target="_blank" rel="noopener noreferrer"><code>-Wextra</code><span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a> and other warning flags which are not automatically enabled by <code>-Wall</code> and <code>-Wextra</code>.</p> <p>If the code expects a specific C++ standard, specify which standard to use by including the <a href="https://gcc.gnu.org/onlinedocs/gcc/C-Dialect-Options.html#index-std-112" target="_blank" rel="noopener noreferrer"><code>-std=</code><span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a> flag. Supported values correspond to the year of finalization for each version of the ISO C++ standard. As of GCC 6.1.0, valid values for the <code>std=</code> flag are <code>c++98</code>/<code>c++03</code>, <code>c++11</code>, <code>c++14</code>, and <code>c++17</code>/<code>c++1z</code>. Values separated by a forward slash are equivalent.</p> <div class="language-cpp extra-class"><pre class="language-cpp"><code>g<span class="token operator">++</span> <span class="token operator">-</span>std<span class="token operator">=</span>c<span class="token operator">++</span><span class="token number">11</span> <span class="token operator"><</span>file<span class="token operator">></span>
</code></pre></div><p>GCC includes some compiler-specific extensions that are disabled when they conflict with a standard specified by the <code>-std=</code> flag. To compile with all extensions enabled, the value <code>gnu++XX</code> may be used, where <code>XX</code> is any of the years used by the <code>c++</code> values listed above.</p> <p>The default standard will be used if none is specified. For versions of GCC prior to 6.1.0, the default is <code>-std=gnu++03</code>; in GCC 6.1.0 and greater, the default is <code>-std=gnu++14</code>.</p> <p>Note that due to bugs in GCC, the <code>-pthread</code> flag must be present at compilation and linking for GCC to support the C++ standard threading functionality introduced with C++11, such as <code>std::thread</code> and <code>std::wait_for</code>. Omitting it when using threading functions may result in <a href="https://gcc.gnu.org/bugzilla/show_bug.cgi?id=58929" target="_blank" rel="noopener noreferrer">no warnings but invalid results<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a> on some platforms.</p> <h3 id="linking-with-libraries"><a href="#linking-with-libraries" class="header-anchor">#</a> Linking with libraries:</h3> <p>Use the <code>-l</code> option to pass the library name:</p> <div class="language-cpp extra-class"><pre class="language-cpp"><code>g<span class="token operator">++</span> main<span class="token punctuation">.</span>cpp <span class="token operator">-</span>lpcre2<span class="token operator">-</span><span class="token number">8</span>
<span class="token macro property"><span class="token directive-hash">#</span><span class="token directive keyword">pcre</span><span class="token expression"><span class="token number">2</span><span class="token operator">-</span><span class="token number">8</span> is the PCRE2 library <span class="token keyword">for</span> <span class="token number">8</span>bit code <span class="token function">units</span> <span class="token punctuation">(</span>UTF<span class="token operator">-</span><span class="token number">8</span><span class="token punctuation">)</span></span></span>
</code></pre></div><p>If the library is not in the standard library path, add the path with <code>-L</code> option:</p> <div class="language-cpp extra-class"><pre class="language-cpp"><code>g<span class="token operator">++</span> main<span class="token punctuation">.</span>cpp <span class="token operator">-</span>L<span class="token operator">/</span>my<span class="token operator">/</span>custom<span class="token operator">/</span>path<span class="token operator">/</span> <span class="token operator">-</span>lmylib
</code></pre></div><p>Multiple libraries can be linked together:</p> <div class="language-cpp extra-class"><pre class="language-cpp"><code>g<span class="token operator">++</span> main<span class="token punctuation">.</span>cpp <span class="token operator">-</span>lmylib1 <span class="token operator">-</span>lmylib2 <span class="token operator">-</span>lmylib3
</code></pre></div><p>If one library depends on another, put the dependent library <strong>before</strong> the independent library:</p> <div class="language-cpp extra-class"><pre class="language-cpp"><code>g<span class="token operator">++</span> main<span class="token punctuation">.</span>cpp <span class="token operator">-</span>lchild<span class="token operator">-</span>lib <span class="token operator">-</span>lbase<span class="token operator">-</span>lib
</code></pre></div><p>Or let the linker determine the ordering itself via <code>--start-group</code> and <code>--end-group</code> (note: this has significant performance cost):</p> <div class="language-cpp extra-class"><pre class="language-cpp"><code>g<span class="token operator">++</span> main<span class="token punctuation">.</span>cpp <span class="token operator">-</span>Wl<span class="token punctuation">,</span><span class="token operator">--</span>start<span class="token operator">-</span>group <span class="token operator">-</span>lbase<span class="token operator">-</span>lib <span class="token operator">-</span>lchild<span class="token operator">-</span>lib <span class="token operator">-</span>Wl<span class="token punctuation">,</span><span class="token operator">--</span>end<span class="token operator">-</span>group
</code></pre></div><h2 id="compiling-with-visual-studio-graphical-interface-hello-world"><a href="#compiling-with-visual-studio-graphical-interface-hello-world" class="header-anchor">#</a> Compiling with Visual Studio (Graphical Interface) - Hello World</h2> <ol><li>Download and install <a href="https://www.visualstudio.com/" target="_blank" rel="noopener noreferrer">Visual Studio Community 2015<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li> <li>Open Visual Studio Community
</li><li>Click File -> New -> Project
<a href="http://i.stack.imgur.com/bFNzb.png" target="_blank" rel="noopener noreferrer"><img src="http://i.stack.imgur.com/bFNzb.png" alt="enter image description here"><span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li> <li>Click Templates -> Visual C++ -> Win32 Console Application and then name the project <strong>MyFirstProgram</strong>.
<a href="http://i.stack.imgur.com/kYTy1.png" target="_blank" rel="noopener noreferrer"><img src="http://i.stack.imgur.com/kYTy1.png" alt="enter image description here"><span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li> <li>Click Ok
</li><li>Click Next in the following window.
<a href="http://i.stack.imgur.com/Rebpz.png" target="_blank" rel="noopener noreferrer"><img src="http://i.stack.imgur.com/Rebpz.png" alt="enter image description here"><span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li> <li>Check the <code>Empty project</code> box and then click Finish:
<a href="http://i.stack.imgur.com/P0P5J.png" target="_blank" rel="noopener noreferrer"><img src="http://i.stack.imgur.com/P0P5J.png" alt="enter image description here"><span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li> <li>Right click on folder Source File then -> Add --> New Item :
<a href="http://i.stack.imgur.com/DLwEd.png" target="_blank" rel="noopener noreferrer"><img src="http://i.stack.imgur.com/DLwEd.png" alt="enter image description here"><span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li> <li>Select C++ File and name the file main.cpp, then click Add:
<a href="http://i.stack.imgur.com/zQaws.png" target="_blank" rel="noopener noreferrer"><img src="http://i.stack.imgur.com/zQaws.png" alt="enter image description here"><span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a>
10: Copy and paste the following code in the new file main.cpp:</li></ol> <div class="language-cpp extra-class"><pre class="language-cpp"><code><span class="token macro property"><span class="token directive-hash">#</span><span class="token directive keyword">include</span> <span class="token string"><iostream></span></span>
<span class="token keyword">int</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token punctuation">{</span>
std<span class="token double-colon punctuation">::</span>cout <span class="token operator"><<</span> <span class="token string">"Hello World!\n"</span><span class="token punctuation">;</span>
<span class="token keyword">return</span> <span class="token number">0</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre></div><p>You environment should look like:
<a href="http://i.stack.imgur.com/vTBkv.png" target="_blank" rel="noopener noreferrer"><img src="http://i.stack.imgur.com/vTBkv.png" alt="enter image description here"><span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></p> <ol><li>Click Debug -> Start <strong>Without</strong> Debugging (or press ctrl + F5) :</li></ol> <p><a href="http://i.stack.imgur.com/B3twO.png" target="_blank" rel="noopener noreferrer"><img src="http://i.stack.imgur.com/B3twO.png" alt="enter image description here"><span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></p> <li>Done. You should get the following console output :
[<img src="http://i.stack.imgur.com/1AwnS.png" alt="enter image description here">](http://i.stack.imgur.com/1AwnS.png)</li> <h2 id="online-compilers"><a href="#online-compilers" class="header-anchor">#</a> Online Compilers</h2> <p>Various websites provide online access to C++ compilers. Online compiler's feature set vary significantly from site to site, but usually they allow to do the following:</p> <ul><li>Paste your code into a web form in the browser.</li> <li>Select some compiler options and compile the code.</li> <li>Collect compiler and/or program output.</li></ul> <p>Online compiler website behavior is usually quite restrictive as they allow anyone to run compilers and execute arbitrary code on their server side, whereas ordinarily remote arbitrary code execution is considered as vulnerability.</p> <p>Online compilers may be useful for the following purposes:</p> <ul><li>Run a small code snippet from a machine which lacks C++ compiler (smartphones, tablets, etc.).</li> <li>Ensure that code compiles successfully with different compilers and runs the same way regardless the compiler it was compiled with.</li> <li>Learn or teach basics of C++.</li> <li>Learn modern C++ features (C++14 and C++17 in near future) when up-to-date C++ compiler is not available on local machine.</li> <li>Spot a bug in your compiler by comparison with a large set of other compilers. Check if a compiler bug was fixed in future versions, which are unavailable on your machine.</li> <li>Solve online judge problems.</li></ul> <p>What online compilers should <strong>not</strong> be used for:</p> <ul><li>Develop full-featured (even small) applications using C++. Usually online compilers do not allow to link with third-party libraries or download build artifacts.</li> <li>Perform intensive computations. Sever-side computing resources are limited, so any user-provided program will be killed after a few seconds of execution. The permitted execution time is usually enough for testing and learning.</li> <li>Attack compiler server itself or any third-party hosts on the net.</li></ul> <p>Examples:</p> <blockquote></blockquote> <p>Disclaimer: documentation author(s) are not affiliated with any resources listed below. Websites are listed alphabetically.</p> <ul><li><a href="http://codepad.org/" target="_blank" rel="noopener noreferrer">http://codepad.org/<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a> Online compiler with code sharing. Editing code after compiling with a source code warning or error does not work so well.</li> <li><a href="http://coliru.stacked-crooked.com/" target="_blank" rel="noopener noreferrer">http://coliru.stacked-crooked.com/<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a> Online compiler for which you specify the command line. Provides both GCC and Clang compilers for use.</li> <li><a href="http://cpp.sh/" target="_blank" rel="noopener noreferrer">http://cpp.sh/<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a> - Online compiler with C++14 support. Does not allow you to edit compiler command line, but some options are available via GUI controls.</li> <li><a href="https://gcc.godbolt.org/" target="_blank" rel="noopener noreferrer">https://gcc.godbolt.org/<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a> - Provides a wide list of compiler versions, architectures, and disassembly output. Very useful when you need to inspect what your code compiles into by different compilers. GCC, Clang, MSVC (<code>CL</code>), Intel compiler (<code>icc</code>), ELLCC, and Zapcc are present, with one or more of these compilers available for the ARM, ARMv8 (as ARM64), Atmel AVR, MIPS, MIPS64, MSP430, PowerPC, x86, and x64 architecutres. Compiler command line arguments may be edited.</li> <li><a href="https://ideone.com/" target="_blank" rel="noopener noreferrer">https://ideone.com/<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a> - Widely used on the Net to illustrate code snippet behavior. Provides both GCC and Clang for use, but doesn't allow you to edit the compiler command line.</li> <li><a href="http://melpon.org/wandbox" target="_blank" rel="noopener noreferrer">http://melpon.org/wandbox<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a> - Supports numerous Clang and GNU/GCC compiler versions.</li> <li><a href="http://onlinegdb.com/" target="_blank" rel="noopener noreferrer">http://onlinegdb.com/<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a> - An extremely minimalistic IDE that includes an editor, a compiler (gcc), and a debugger (gdb).</li> <li><a href="http://rextester.com/" target="_blank" rel="noopener noreferrer">http://rextester.com/<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a> - Provides Clang, GCC, and Visual Studio compilers for both C and C++ (along with compilers for other languages), with the Boost library available for use.</li> <li><a href="http://tutorialspoint.com/compile_cpp11_online.php" target="_blank" rel="noopener noreferrer">http://tutorialspoint.com/compile_cpp11_online.php<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a> - Full-featured UNIX shell with GCC, and a user-friendly project explorer.</li> <li><a href="http://webcompiler.cloudapp.net/" target="_blank" rel="noopener noreferrer">http://webcompiler.cloudapp.net/<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a> - Online Visual Studio 2015 compiler, provided by Microsoft as part of RiSE4fun.</li></ul> <h2 id="compiling-with-visual-c-command-line"><a href="#compiling-with-visual-c-command-line" class="header-anchor">#</a> Compiling with Visual C++ (Command Line)</h2> <p>For programmers coming from GCC or Clang to Visual Studio, or programmers more comfortable with the command line in general, you can use the Visual C++ compiler from the command line as well as the IDE.</p> <p>If you desire to compile your code from the command line in Visual Studio, you first need to set up the command line environment. This can be done either by opening the <a href="https://msdn.microsoft.com/en-us/library/f2ccy3wt.aspx#Anchor_0" target="_blank" rel="noopener noreferrer"><code>Visual Studio Command Prompt</code>/<code>Developer Command Prompt</code>/<code>x86 Native Tools Command Prompt</code>/<code>x64 Native Tools Command Prompt</code> or similar<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a> (as provided by your version of Visual Studio), or at the command prompt, by navigating to the <code>VC</code> subdirectory of the compiler's install directory (typically <code>\Program Files (x86)\Microsoft Visual Studio x\VC</code>, where <code>x</code> is the version number (such as <code>10.0</code> for 2010, or <code>14.0</code> for 2015) and running the <code>VCVARSALL</code> batch file with a command-line parameter specified <a href="https://msdn.microsoft.com/en-us/library/f2ccy3wt.aspx#Anchor_1" target="_blank" rel="noopener noreferrer">here<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a>.</p> <p>Note that unlike GCC, Visual Studio doesn't provide a front-end for the linker (<code>link.exe</code>) via the compiler (<code>cl.exe</code>), but instead provides the linker as a separate program, which the compiler calls as it exits. <code>cl.exe</code> and <code>link.exe</code> can be used separately with different files and options, or <code>cl</code> can be told to pass files and options to <code>link</code> if both tasks are done together. Any linking options specified to <code>cl</code> will be translated into options for <code>link</code>, and any files not processed by <code>cl</code> will be passed directly to <code>link</code>. As this is mainly a simple guide to compiling with the Visual Studio command line, arguments for <code>link</code> will not be described at this time; if you need a list, see <a href="https://msdn.microsoft.com/en-us/library/y0zzbyt4.aspx" target="_blank" rel="noopener noreferrer">here<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a>.</p> <p>Note that arguments to <code>cl</code> are case-sensitive, while arguments to <code>link</code> are not.</p> <p>[Be advised that some of the following examples use the Windows shell "current directory" variable, <code>%cd%</code>, when specifying absolute path names. For anyone unfamiliar with this variable, it expands to the current working directory. From the command line, it will be the directory you were in when you ran <code>cl</code>, and is specified in the command prompt by default (if your command prompt is <code>C:\src></code>, for example, then <code>%cd%</code> is <code>C:\src\</code>).]</p> <p>Assuming a single source file named <code>main.cpp</code> in the current folder, the command to compile and link an unoptimised executable (useful for initial development and debugging) is (use either of the following):</p> <div class="language-cpp extra-class"><pre class="language-cpp"><code>cl main<span class="token punctuation">.</span>cpp
<span class="token comment">// Generates object file "main.obj".</span>
<span class="token comment">// Performs linking with "main.obj".</span>
<span class="token comment">// Generates executable "main.exe".</span>
cl <span class="token operator">/</span>Od main<span class="token punctuation">.</span>cpp
<span class="token comment">// Same as above.</span>
<span class="token comment">// "/Od" is the "Optimisation: disabled" option, and is the default when no /O is specified.</span>
</code></pre></div><p>Assuming an additional source file "niam.cpp" in the same directory, use the following:</p> <div class="language-cpp extra-class"><pre class="language-cpp"><code>cl main<span class="token punctuation">.</span>cpp niam<span class="token punctuation">.</span>cpp
<span class="token comment">// Generates object files "main.obj" and "niam.obj".</span>
<span class="token comment">// Performs linking with "main.obj" and "niam.obj".</span>
<span class="token comment">// Generates executable "main.exe".</span>
</code></pre></div><p>You can also use wildcards, as one would expect:</p> <div class="language-cpp extra-class"><pre class="language-cpp"><code>cl main<span class="token punctuation">.</span>cpp src\<span class="token operator">*</span><span class="token punctuation">.</span>cpp
<span class="token comment">// Generates object file "main.obj", plus one object file for each ".cpp" file in folder</span>
<span class="token comment">// "%cd%\src".</span>
<span class="token comment">// Performs linking with "main.obj", and every additional object file generated.</span>
<span class="token comment">// All object files will be in the current folder.</span>
<span class="token comment">// Generates executable "main.exe".</span>
</code></pre></div><p>To rename or relocate the executable, use one of the following:</p> <div class="language-cpp extra-class"><pre class="language-cpp"><code>cl <span class="token operator">/</span>o name main<span class="token punctuation">.</span>cpp
<span class="token comment">// Generates executable named "name.exe".</span>
cl <span class="token operator">/</span>o folder\ main<span class="token punctuation">.</span>cpp
<span class="token comment">// Generates executable named "main.exe", in folder "%cd%\folder".</span>
cl <span class="token operator">/</span>o folder\name main<span class="token punctuation">.</span>cpp
<span class="token comment">// Generates executable named "name.exe", in folder "%cd%\folder".</span>
cl <span class="token operator">/</span>Fename main<span class="token punctuation">.</span>cpp
<span class="token comment">// Same as "/o name".</span>
cl <span class="token operator">/</span>Fefolder\ main<span class="token punctuation">.</span>cpp
<span class="token comment">// Same as "/o folder\".</span>
cl <span class="token operator">/</span>Fefolder\name main<span class="token punctuation">.</span>cpp
<span class="token comment">// Same as "/o folder\name".</span>
</code></pre></div><p>Both <code>/o</code> and <code>/Fe</code> pass their parameter (let's call it <code>o-param</code>) to <code>link</code> as <code>/OUT:o-param</code>, appending the appropriate extension (generally <code>.exe</code> or <code>.dll</code>) to "name" <code>o-param</code>s as necessary. While both <code>/o</code> and <code>/Fe</code> are to my knowledge identical in functionality, the latter is preferred for Visual Studio. <code>/o</code> is marked as deprecated, and appears to mainly be provided for programmers more familiar with GCC or Clang.</p> <p>Note that while the space between <code>/o</code> and the specified folder and/or name is optional, there <strong>cannot</strong> be a space between <code>/Fe</code> and the specified folder and/or name.</p> <p>Similarly, to produce an optimised executable (for use in production), use:</p> <div class="language-cpp extra-class"><pre class="language-cpp"><code>cl <span class="token operator">/</span>O1 main<span class="token punctuation">.</span>cpp
<span class="token comment">// Optimise for executable size. Produces small programs, at the possible expense of slower</span>
<span class="token comment">// execution.</span>
cl <span class="token operator">/</span>O2 main<span class="token punctuation">.</span>cpp
<span class="token comment">// Optimise for execution speed. Produces fast programs, at the possible expense of larger</span>
<span class="token comment">// file size.</span>
cl <span class="token operator">/</span>GL main<span class="token punctuation">.</span>cpp other<span class="token punctuation">.</span>cpp
<span class="token comment">// Generates special object files used for whole-program optimisation, which allows CL to</span>
<span class="token comment">// take every module (translation unit) into consideration during optimisation.</span>
<span class="token comment">// Passes the option "/LTCG" (Link-Time Code Generation) to LINK, telling it to call CL during</span>
<span class="token comment">// the linking phase to perform additional optimisations. If linking is not performed at this</span>
<span class="token comment">// time, the generated object files should be linked with "/LTCG".</span>
<span class="token comment">// Can be used with other CL optimisation options.</span>
</code></pre></div><p>Finally, to produce a platform-specific optimized executable (for use in production on the machine with the specified architecture), choose the appropriate command prompt or <a href="https://msdn.microsoft.com/en-us/library/x4d2c09s.aspx" target="_blank" rel="noopener noreferrer"><code>VCVARSALL</code> parameter<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a> for the target platform. <code>link</code> should detect the desired platform from the object files; if not, use the <a href="https://msdn.microsoft.com/en-us/library/5wy54dk2.aspx" target="_blank" rel="noopener noreferrer"><code>/MACHINE</code> option<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a> to explicitly specify the target platform.</p> <div class="language-cpp extra-class"><pre class="language-cpp"><code><span class="token comment">// If compiling for x64, and LINK doesn't automatically detect target platform:</span>
cl main<span class="token punctuation">.</span>cpp <span class="token operator">/</span>link <span class="token operator">/</span>machine<span class="token operator">:</span>X64
</code></pre></div><p>Any of the above will produce an executable with the name specified by <code>/o</code> or <code>/Fe</code>, or if neither is provided, with a name identical to the first source or object file specified to the compiler.</p> <div class="language-cpp extra-class"><pre class="language-cpp"><code>cl a<span class="token punctuation">.</span>cpp b<span class="token punctuation">.</span>cpp c<span class="token punctuation">.</span>cpp
<span class="token comment">// Generates "a.exe".</span>
cl d<span class="token punctuation">.</span>obj a<span class="token punctuation">.</span>cpp q<span class="token punctuation">.</span>cpp
<span class="token comment">// Generates "d.exe".</span>
cl y<span class="token punctuation">.</span>lib n<span class="token punctuation">.</span>cpp o<span class="token punctuation">.</span>obj
<span class="token comment">// Generates "n.exe".</span>
cl <span class="token operator">/</span>o yo zp<span class="token punctuation">.</span>obj pz<span class="token punctuation">.</span>cpp
<span class="token comment">// Generates "yo.exe".</span>
</code></pre></div><p>To compile a file(s) without linking, use:</p> <div class="language-cpp extra-class"><pre class="language-cpp"><code>cl <span class="token operator">/</span>c main<span class="token punctuation">.</span>cpp
<span class="token comment">// Generates object file "main.obj".</span>
</code></pre></div><p>This tells <code>cl</code> to exit without calling <code>link</code>, and produces an object file, which can later be linked with other files to produce a binary.</p> <div class="language-cpp extra-class"><pre class="language-cpp"><code>cl main<span class="token punctuation">.</span>obj niam<span class="token punctuation">.</span>cpp
<span class="token comment">// Generates object file "niam.obj".</span>
<span class="token comment">// Performs linking with "main.obj" and "niam.obj".</span>
<span class="token comment">// Generates executable "main.exe".</span>
link main<span class="token punctuation">.</span>obj niam<span class="token punctuation">.</span>obj
<span class="token comment">// Performs linking with "main.obj" and "niam.obj".</span>
<span class="token comment">// Generates executable "main.exe".</span>
</code></pre></div><p>There are other valuable command line parameters as well, which it would be very useful for users to know:</p> <div class="language-cpp extra-class"><pre class="language-cpp"><code>cl <span class="token operator">/</span>EHsc main<span class="token punctuation">.</span>cpp
<span class="token comment">// "/EHsc" specifies that only standard C++ ("synchronous") exceptions will be caught,</span>
<span class="token comment">// and `extern "C"` functions will not throw exceptions.</span>
<span class="token comment">// This is recommended when writing portable, platform-independent code.</span>
cl <span class="token operator">/</span>clr main<span class="token punctuation">.</span>cpp
<span class="token comment">// "/clr" specifies that the code should be compiled to use the common language runtime,</span>
<span class="token comment">// the .NET Framework's virtual machine.</span>
<span class="token comment">// Enables the use of Microsoft's C++/CLI language in addition to standard ("native") C++,</span>
<span class="token comment">// and creates an executable that requires .NET to run.</span>
cl <span class="token operator">/</span>Za main<span class="token punctuation">.</span>cpp
<span class="token comment">// "/Za" specifies that Microsoft extensions should be disabled, and code should be</span>
<span class="token comment">// compiled strictly according to ISO C++ specifications.</span>
<span class="token comment">// This is recommended for guaranteeing portability.</span>
cl <span class="token operator">/</span>Zi main<span class="token punctuation">.</span>cpp
<span class="token comment">// "/Zi" generates a program database (PDB) file for use when debugging a program, without</span>
<span class="token comment">// affecting optimisation specifications, and passes the option "/DEBUG" to LINK.</span>
cl <span class="token operator">/</span>LD dll<span class="token punctuation">.</span>cpp
<span class="token comment">// "/LD" tells CL to configure LINK to generate a DLL instead of an executable.</span>
<span class="token comment">// LINK will output a DLL, in addition to an LIB and EXP file for use when linking.</span>
<span class="token comment">// To use the DLL in other programs, pass its associated LIB to CL or LINK when compiling those</span>
<span class="token comment">// programs.</span>
cl main<span class="token punctuation">.</span>cpp <span class="token operator">/</span>link <span class="token operator">/</span>LINKER_OPTION
<span class="token comment">// "/link" passes everything following it directly to LINK, without parsing it in any way.</span>
<span class="token comment">// Replace "/LINKER_OPTION" with any desired LINK option(s).</span>
</code></pre></div><p>For anyone more familiar with *nix systems and/or GCC/Clang, <code>cl</code>, <code>link</code>, and other Visual Studio command line tools can accept parameters specified with a hyphen (such as <code>-c</code>) instead of a slash (such as <code>/c</code>). Additionally, Windows recognises either a slash or a backslash as a valid path separator, so *nix-style paths can be used as well. This makes it easy to convert simple compiler command lines from <code>g++</code> or <code>clang++</code> to <code>cl</code>, or vice versa, with minimal changes.</p> <div class="language-cpp extra-class"><pre class="language-cpp"><code>g<span class="token operator">++</span> <span class="token operator">-</span>o app src<span class="token operator">/</span>main<span class="token punctuation">.</span>cpp
cl <span class="token operator">-</span>o app src<span class="token operator">/</span>main<span class="token punctuation">.</span>cpp
</code></pre></div><p>Of course, when porting command lines that use more complex <code>g++</code> or <code>clang++</code> options, you need to look up equivalent commands in the applicable compiler documentations and/or on resource sites, but this makes it easier to get things started with minimal time spent learning about new compilers.</p> <p>In case you need specific language features for your code, a specific release of MSVC was required. From <a href="https://blogs.msdn.microsoft.com/vcblog/2016/06/07/standards-version-switches-in-the-compiler/" target="_blank" rel="noopener noreferrer">Visual C++ 2015 Update 3<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a> on it is possible to choose the version of the standard to compile with via the <code>/std</code> flag. Possible values are <code>/std:c++14</code> and <code>/std:c++latest</code> (<code>/std:c++17</code> will follow soon).</p> <p>Note: In older versions of this compiler, specific feature flags were available however this was mostly used for previews of new features.</p> <h2 id="compiling-with-clang"><a href="#compiling-with-clang" class="header-anchor">#</a> Compiling with Clang</h2> <p>As the <a href="http://clang.llvm.org/" target="_blank" rel="noopener noreferrer">Clang<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a> front-end is designed for being compatible with GCC, most programs that can be compiled via <a href="https://stackoverflow.com/documentation/c%2B%2B/206/introduction-to-c/1334/compiling-with-gcc" target="_blank" rel="noopener noreferrer">GCC<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a> will compile when you swap <code>g++</code> by <code>clang++</code> in the build scripts. If no <code>-std=version</code> is given, gnu11 will be used.</p> <p>Windows users who are used to <a href="https://stackoverflow.com/documentation/c%2B%2B/206/introduction-to-c/5959/compiling-with-visual-c-command-line" target="_blank" rel="noopener noreferrer">MSVC<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a> can swap <code>cl.exe</code> with <code>clang-cl.exe</code>. By default, clang tries to be compatible with the highest version of MSVC that has been installed.</p> <p>In the case of compiling with visual studio, clang-cl can be used by changing the <code>Platform toolset</code> in the project properties.</p> <p>In both cases, clang is only compatible via its front-end, though it also tries to generate binary compatible object files. Users of clang-cl should note that <a href="http://clang.llvm.org/docs/MSVCCompatibility.html" target="_blank" rel="noopener noreferrer">the compatibility with MSVC is not complete yet<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a>.</p> <p>To use clang or clang-cl, one could use the default installation on certain Linux distributions or those bundled with IDEs (like XCode on Mac). For other versions of this compiler or on platforms which don't have this installed, this can be download from the <a href="http://llvm.org/releases/download.html" target="_blank" rel="noopener noreferrer">official download page<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a>.</p> <p>If you're using CMake to build your code you can usually switch the compiler by setting the <code>CC</code> and <code>CXX</code> environment variables like this:</p> <div class="language-cpp extra-class"><pre class="language-cpp"><code>mkdir build
cd build
CC<span class="token operator">=</span>clang CXX<span class="token operator">=</span>clang<span class="token operator">++</span> cmake <span class="token punctuation">.</span><span class="token punctuation">.</span>
cmake <span class="token operator">--</span>build <span class="token punctuation">.</span>
</code></pre></div><p>See also <a href="http://stackoverflow.com/documentation/cmake/862/introduction-to-cmake#t=201608042347032067346" target="_blank" rel="noopener noreferrer">introduction to Cmake<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a>.</p> <h2 id="the-c-compilation-process"><a href="#the-c-compilation-process" class="header-anchor">#</a> The C++ compilation process</h2> <p>When you develop a C++ program, the next step is to compile the program before running it. The compilation is the process which converts the program written in human readable language like C, C++ etc into a machine code, directly understood by the Central Processing Unit. For example, if you have a C++ source code file named prog.cpp and you execute the compile command,</p> <div class="language- extra-class"><pre class="language-text"><code>
g++ -Wall -ansi -o prog prog.cpp
</code></pre></div><p>There are 4 main stages involved in creating an executable file from the source file.</p> <li>
The C++ the preprocessor takes a C++ source code file and deals with the headers(#include), macros(#define) and other preprocessor directives.
</li> <li><p>The expanded C++ source code file produced by the C++ preprocessor is
compiled into the assembly language for the platform.</p></li> <li><p>The assembler code generated by the compiler is assembled into the
object code for the platform.</p></li> <li><p>The object code file produced by the assembler is linked together<br>
with the object code files for any library functions used to produce
either a library or an executable file.</p></li> <p><strong>Preprocessing</strong></p> <p>The preprocessor handles the preprocessor directives, like #include and #define. It is agnostic of the syntax of C++, which is why it must be used with care.</p> <p>It works on one C++ source file at a time by replacing #include directives with the content of the respective files (which is usually just declarations), doing replacement of macros (#define), and selecting different portions of text depending of #if, #ifdef and #ifndef directives.</p> <p>The preprocessor works on a stream of preprocessing tokens. Macro substitution is defined as replacing tokens with other tokens (the operator ## enables merging two tokens when it make sense).</p> <p>After all this, the preprocessor produces a single output that is a stream of tokens resulting from the transformations described above. It also adds some special markers that tell the compiler where each line came from so that it can use those to produce sensible error messages.</p> <p>Some errors can be produced at this stage with clever use of the #if and #error directives.</p> <p>By using below compiler flag, we can stop the process at preprocessing stage.</p> <div class="language-cpp extra-class"><pre class="language-cpp"><code>g<span class="token operator">++</span> <span class="token operator">-</span>E prog<span class="token punctuation">.</span>cpp
</code></pre></div><p><strong>Compilation</strong></p> <p>The compilation step is performed on each output of the preprocessor. The compiler parses the pure C++ source code (now without any preprocessor directives) and converts it into assembly code. Then invokes underlying back-end(assembler in toolchain) that assembles that code into machine code producing actual binary file in some format(ELF, COFF, a.out, ...). This object file contains the compiled code (in binary form) of the symbols defined in the input. Symbols in object files are referred to by name.</p> <p>Object files can refer to symbols that are not defined. This is the case when you use a declaration, and don't provide a definition for it. The compiler doesn't mind this, and will happily produce the object file as long as the source code is well-formed.</p> <p>Compilers usually let you stop compilation at this point. This is very useful because with it you can compile each source code file separately. The advantage this provides is that you don't need to recompile everything if you only change a single file.</p> <p>The produced object files can be put in special archives called static libraries, for easier reusing later on.</p> <p>It's at this stage that "regular" compiler errors, like syntax errors or failed overload resolution errors, are reported.</p> <p>In order to stop the process after the compile step, we can use the -S option:</p> <div class="language-cpp extra-class"><pre class="language-cpp"><code>g<span class="token operator">++</span> <span class="token operator">-</span>Wall <span class="token operator">-</span>ansi <span class="token operator">-</span>S prog<span class="token punctuation">.</span>cpp
</code></pre></div><p><strong>Assembling</strong></p> <p>The assembler creates object code. On a UNIX system you may see files with a .o suffix (.OBJ on MSDOS) to indicate object code files. In this phase the assembler converts those object files from assembly code into machine level instructions and the file created is a relocatable object code. Hence, the compilation phase generates the relocatable object program and this program can be used in different places without having to compile again.</p> <p>To stop the process after the assembly step, you can use the -c option:</p> <div class="language-cpp extra-class"><pre class="language-cpp"><code>g<span class="token operator">++</span> <span class="token operator">-</span>Wall <span class="token operator">-</span>ansi <span class="token operator">-</span>c prog<span class="token punctuation">.</span>cpp
</code></pre></div><p><strong>Linking</strong></p> <p>The linker is what produces the final compilation output from the object files the assembler produced. This output can be either a shared (or dynamic) library (and while the name is similar, they don't have much in common with static libraries mentioned earlier) or an executable.</p> <p>It links all the object files by replacing the references to undefined symbols with the correct addresses. Each of these symbols can be defined in other object files or in libraries. If they are defined in libraries other than the standard library, you need to tell the linker about them.</p> <p>At this stage the most common errors are missing definitions or duplicate definitions. The former means that either the definitions don't exist (i.e. they are not written), or that the object files or libraries where they reside were not given to the linker. The latter is obvious: the same symbol was defined in two different object files or libraries.</p> <h2 id="compiling-with-code-blocks-graphical-interface"><a href="#compiling-with-code-blocks-graphical-interface" class="header-anchor">#</a> Compiling with Code::Blocks (Graphical interface)</h2> <li>
Download and install Code::Blocks [here](http://www.codeblocks.org/downloads/binaries). If you're on Windows, be careful to select a file for which the name contains `mingw`, the other files don't install any compiler.
</li> <li>
Open Code::Blocks and click on "Create a new project":
[<img src="https://i.stack.imgur.com/z4Oll.png" alt="enter image description here">](https://i.stack.imgur.com/z4Oll.png)
</li> <li>
Select "Console application" and click "Go":
[<img src="https://i.stack.imgur.com/0wBAn.png" alt="enter image description here">](https://i.stack.imgur.com/0wBAn.png)
</li> <li>
Click "Next", select "C++", click "Next", select a name for your project and choose a folder to save it in, click "Next" and then click "Finish".
</li> <li>
Now you can edit and compile your code. A default code that prints "Hello world!" in the console is already there. To compile and/or run your program, press one of the three compile/run buttons in the toolbar:
[<img src="https://i.stack.imgur.com/wCmdw.png" alt="enter image description here">](https://i.stack.imgur.com/wCmdw.png)
To compile without running, press [<img src="https://i.stack.imgur.com/gOkY9.png" alt="Build">](https://i.stack.imgur.com/gOkY9.png), to run without compiling again, press [<img src="https://i.stack.imgur.com/eLjbt.png" alt="Run">](https://i.stack.imgur.com/eLjbt.png) and to compile and then run, press [<img src="https://i.stack.imgur.com/Zgyi8.png" alt="Build and run">](https://i.stack.imgur.com/Zgyi8.png).
Compiling and running the default "Hello world!" code gives the following result:
[<img src="https://i.stack.imgur.com/qbVy8.png" alt="enter image description here">](https://i.stack.imgur.com/qbVy8.png)
</li> <h4 id="remarks"><a href="#remarks" class="header-anchor">#</a> Remarks</h4> <p>Most operating systems ship without a compiler, and they have to be installed later. Some common compilers choices are:</p> <ul><li><a href="https://gcc.gnu.org/" target="_blank" rel="noopener noreferrer">GCC, the GNU Compiler Collection<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a> <a href="/questions/tagged/g%2b%2b">g++</a></li> <li><a href="http://clang.llvm.org/" target="_blank" rel="noopener noreferrer">clang: a C language family frontend for LLVM<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a> <a href="/questions/tagged/clang%2b%2b">clang++</a></li> <li><a href="https://www.visualstudio.com/" target="_blank" rel="noopener noreferrer">MSVC, Microsoft Visual C++ (included in Visual Studio)<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a> <a href="/questions/tagged/visual-c%2b%2b">visual-c++</a></li> <li><a href="https://www.embarcadero.com/products/cbuilder" target="_blank" rel="noopener noreferrer">C++Builder, Embarcadero C++Builder<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a> (included in RAD Studio) <a href="/questions/tagged/c%2b%2bbuilder">c++builder</a></li></ul> <p>Please consult the appropriate compiler manual, on how to compile a C++ program.</p> <p>Another option to use a specific compiler with its own specific build system, it is possible to let generic <a href="https://stackoverflow.com/documentation/c%2B%2B/8200/build-systems" target="_blank" rel="noopener noreferrer">build systems<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a> configure the project for a specific compiler or for the default installed one.</p></div> <footer class="page-edit"><div class="edit-link"><a href="https://github.com/devtut/generate/edit/master/docs/cpp/compiling-and-building.md" target="_blank" rel="noopener noreferrer">Edit this page on GitHub</a> <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></div> <!----></footer> <div class="page-nav"><p class="inner"><span class="prev">
←
<a href="/cpp/side-by-side-comparisons-of-classic-c-examples-solved-via-c-vs-c-11-vs-c-14-vs-c-17.html" class="prev">
Side by Side Comparisons of classic C++ examples solved via C++ vs C++11 vs C++14 vs C++17
</a></span> <span class="next"><a href="/cpp/common-compile-linker-errors-gcc.html">
Common compile/linker errors (GCC)
</a>
→
</span></p></div> </main></div><div class="global-ui"><!----></div></div>
<script src="/assets/js/app.1779e102.js" defer></script><script src="/assets/js/3.2cfa8016.js" defer></script><script src="/assets/js/632.7ab15d44.js" defer></script>
</body>
</html>