1*67e74705SXin Li<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" 2*67e74705SXin Li "http://www.w3.org/TR/html4/strict.dtd"> 3*67e74705SXin Li<html> 4*67e74705SXin Li<head> 5*67e74705SXin Li <title>scan-build: running the analyzer from the command line</title> 6*67e74705SXin Li <link type="text/css" rel="stylesheet" href="content.css"> 7*67e74705SXin Li <link type="text/css" rel="stylesheet" href="menu.css"> 8*67e74705SXin Li <script type="text/javascript" src="scripts/menu.js"></script> 9*67e74705SXin Li</head> 10*67e74705SXin Li<body> 11*67e74705SXin Li 12*67e74705SXin Li<div id="page"> 13*67e74705SXin Li<!--#include virtual="menu.html.incl"--> 14*67e74705SXin Li<div id="content"> 15*67e74705SXin Li 16*67e74705SXin Li<h1>scan-build: running the analyzer from the command line</h1> 17*67e74705SXin Li 18*67e74705SXin Li<table style="margin-top:0px" width="100%" cellpadding="0px" cellspacing="0"> 19*67e74705SXin Li<tr><td> 20*67e74705SXin Li 21*67e74705SXin Li<h3>What is it?</h3> 22*67e74705SXin Li<p><b>scan-build</b> is a command line utility that enables a user to run the 23*67e74705SXin Listatic analyzer over their codebase as part of performing a regular build (from 24*67e74705SXin Lithe command line).</p> 25*67e74705SXin Li 26*67e74705SXin Li<h3>How does it work?</h3> 27*67e74705SXin Li<p>During a project build, as source files are compiled they are also analyzed 28*67e74705SXin Liin tandem by the static analyzer.</p> 29*67e74705SXin Li 30*67e74705SXin Li<p>Upon completion of the build, results are then presented to the user within a 31*67e74705SXin Liweb browser.</p> 32*67e74705SXin Li 33*67e74705SXin Li<h3>Will it work with any build system?</h3> 34*67e74705SXin Li<p><b>scan-build</b> has little or no knowledge about how you build your code. 35*67e74705SXin LiIt works by overriding the <tt>CC</tt> and <tt>CXX</tt> environment variables to 36*67e74705SXin Li(hopefully) change your build to use a "fake" compiler instead of the 37*67e74705SXin Lione that would normally build your project. This fake compiler executes either 38*67e74705SXin Li<tt>clang</tt> or <tt>gcc</tt> (depending on the platform) to compile your 39*67e74705SXin Licode and then executes the static analyzer to analyze your code.</p> 40*67e74705SXin Li 41*67e74705SXin Li<p>This "poor man's interposition" works amazingly well in many cases 42*67e74705SXin Liand falls down in others. Please consult the information on this page on making 43*67e74705SXin Lithe best use of <b>scan-build</b>, which includes getting it to work when the 44*67e74705SXin Liaforementioned hack fails to work.</p> 45*67e74705SXin Li 46*67e74705SXin Li</td> 47*67e74705SXin Li<td style="padding-left:10px; text-align:center"> 48*67e74705SXin Li <img src="images/scan_build_cmd.png" width="450px" alt="scan-build"><br> 49*67e74705SXin Li <a href="images/analyzer_html.png"><img src="images/analyzer_html.png" width="450px" alt="analyzer in browser"></a> 50*67e74705SXin Li<br><b>Viewing static analyzer results in a web browser</b> 51*67e74705SXin Li</td></tr></table> 52*67e74705SXin Li 53*67e74705SXin Li<h2>Contents</h2> 54*67e74705SXin Li 55*67e74705SXin Li<ul> 56*67e74705SXin Li<li><a href="#scanbuild">Getting Started</a> 57*67e74705SXin Li <ul> 58*67e74705SXin Li <li><a href="#scanbuild_basicusage">Basic Usage</a></li> 59*67e74705SXin Li <li><a href="#scanbuild_forwindowsusers">For Windows Users</a></li> 60*67e74705SXin Li <li><a href="#scanbuild_otheroptions">Other Options</a></li> 61*67e74705SXin Li <li><a href="#scanbuild_output">Output of scan-build</a></li> 62*67e74705SXin Li </ul> 63*67e74705SXin Li</li> 64*67e74705SXin Li<li><a href="#recommendedguidelines">Recommended Usage Guidelines</a> 65*67e74705SXin Li <ul> 66*67e74705SXin Li <li><a href="#recommended_debug">Always Analyze a Project in its "Debug" Configuration</a></li> 67*67e74705SXin Li <li><a href="#recommended_verbose">Use Verbose Output when Debugging scan-build</a></li> 68*67e74705SXin Li <li><a href="#recommended_autoconf">Run './configure' through scan-build</a></li> 69*67e74705SXin Li </ul> 70*67e74705SXin Li</li> 71*67e74705SXin Li<li><a href="#iphone">Analyzing iPhone Projects</a></li> 72*67e74705SXin Li</ul> 73*67e74705SXin Li 74*67e74705SXin Li<h2 id="scanbuild">Getting Started</h2> 75*67e74705SXin Li 76*67e74705SXin Li<p>The <tt>scan-build</tt> command can be used to analyze an entire project by 77*67e74705SXin Liessentially interposing on a project's build process. This means that to run the 78*67e74705SXin Lianalyzer using <tt>scan-build</tt>, you will use <tt>scan-build</tt> to analyze 79*67e74705SXin Lithe source files compiled by <tt>gcc</tt>/<tt>clang</tt> during a project build. 80*67e74705SXin LiThis means that any files that are not compiled will also not be analyzed.</p> 81*67e74705SXin Li 82*67e74705SXin Li<h3 id="scanbuild_basicusage">Basic Usage</h3> 83*67e74705SXin Li 84*67e74705SXin Li<p>Basic usage of <tt>scan-build</tt> is designed to be simple: just place the 85*67e74705SXin Liword "scan-build" in front of your build command:</p> 86*67e74705SXin Li 87*67e74705SXin Li<pre class="code_example"> 88*67e74705SXin Li$ <span class="code_highlight">scan-build</span> make 89*67e74705SXin Li$ <span class="code_highlight">scan-build</span> xcodebuild 90*67e74705SXin Li</pre> 91*67e74705SXin Li 92*67e74705SXin Li<p>In the first case <tt>scan-build</tt> analyzes the code of a project built 93*67e74705SXin Liwith <tt>make</tt> and in the second case <tt>scan-build</tt> analyzes a project 94*67e74705SXin Libuilt using <tt>xcodebuild</tt>.<p> 95*67e74705SXin Li 96*67e74705SXin Li<p>Here is the general format for invoking <tt>scan-build</tt>:</p> 97*67e74705SXin Li 98*67e74705SXin Li<pre class="code_example"> 99*67e74705SXin Li$ <span class="code_highlight">scan-build</span> <i>[scan-build options]</i> <span class="code_highlight"><command></span> <i>[command options]</i> 100*67e74705SXin Li</pre> 101*67e74705SXin Li 102*67e74705SXin Li<p>Operationally, <tt>scan-build</tt> literally runs <command> with all of the 103*67e74705SXin Lisubsequent options passed to it. For example, one can pass <tt>-j4</tt> to 104*67e74705SXin Li<tt>make</tt> get a parallel build over 4 cores:</p> 105*67e74705SXin Li 106*67e74705SXin Li<pre class="code_example"> 107*67e74705SXin Li$ scan-build make <span class="code_highlight">-j4</span> 108*67e74705SXin Li</pre> 109*67e74705SXin Li 110*67e74705SXin Li<p>In almost all cases, <tt>scan-build</tt> makes no effort to interpret the 111*67e74705SXin Lioptions after the build command; it simply passes them through. In general, 112*67e74705SXin Li<tt>scan-build</tt> should support parallel builds, but <b>not distributed 113*67e74705SXin Libuilds</b>.</p> 114*67e74705SXin Li 115*67e74705SXin Li<p>It is also possible to use <tt>scan-build</tt> to analyze specific 116*67e74705SXin Lifiles:</p> 117*67e74705SXin Li 118*67e74705SXin Li<pre class="code_example"> 119*67e74705SXin Li $ scan-build gcc -c <span class="code_highlight">t1.c t2.c</span> 120*67e74705SXin Li</pre> 121*67e74705SXin Li 122*67e74705SXin Li<p>This example causes the files <tt>t1.c</tt> and <tt>t2.c</tt> to be analyzed. 123*67e74705SXin Li</p> 124*67e74705SXin Li 125*67e74705SXin Li<h3 id="scanbuild_forwindowsusers">For Windows Users</h3> 126*67e74705SXin Li 127*67e74705SXin Li<p>Windows users must have Perl installed to use scan-build.</p> 128*67e74705SXin Li 129*67e74705SXin Li<p><tt>scan-build.bat</tt> script allows you to launch scan-build in the same 130*67e74705SXin Liway as it described in the Basic Usage section above. To invoke scan-build from 131*67e74705SXin Lian arbitrary location, add the path to the folder containing scan-build.bat to 132*67e74705SXin Liyour PATH environment variable.</p> 133*67e74705SXin Li 134*67e74705SXin Li<p>If you have unexpected compilation/make problems when running scan-build 135*67e74705SXin Liwith MinGW/MSYS the following information may be helpful:</p> 136*67e74705SXin Li 137*67e74705SXin Li<ul> 138*67e74705SXin Li <li> If getting unexpected <tt>"fatal error: no input files"</tt> while 139*67e74705SXin Libuilding with MSYS make from the Windows cmd, try one of these solutions:</li> 140*67e74705SXin Li <ul> 141*67e74705SXin Li <li> Use MinGW <tt>mingw32-make</tt> instead of MSYS <tt>make</tt> and 142*67e74705SXin Liexclude the path to MSYS from PATH to prevent <tt>mingw32-make</tt> from using 143*67e74705SXin LiMSYS utils. MSYS utils are dependent on the MSYS runtime and they are not 144*67e74705SXin Liintended for being run from the Windows cmd. Specifically, makefile commands 145*67e74705SXin Liwith backslashed quotes may be heavily corrupted when passed for execution.</li> 146*67e74705SXin Li <li> Run <tt>make</tt> from the sh shell: 147*67e74705SXin Li<pre class="code_example"> 148*67e74705SXin Li$ <span class="code_highlight">scan-build</span> <i>[scan-build options]</i> sh -c "make <i>[make options]</i>" 149*67e74705SXin Li</pre></li> 150*67e74705SXin Li </ul> 151*67e74705SXin Li <li> If getting <tt>"Error : *** target pattern contains no `%'"</tt> while 152*67e74705SXin Liusing GNU Make 3.81, try to use another version of make.</li> 153*67e74705SXin Li</ul> 154*67e74705SXin Li 155*67e74705SXin Li<h3 id="scanbuild_otheroptions">Other Options</h3> 156*67e74705SXin Li 157*67e74705SXin Li<p>As mentioned above, extra options can be passed to <tt>scan-build</tt>. These 158*67e74705SXin Lioptions prefix the build command. For example:</p> 159*67e74705SXin Li 160*67e74705SXin Li<pre class="code_example"> 161*67e74705SXin Li $ scan-build <span class="code_highlight">-k -V</span> make 162*67e74705SXin Li $ scan-build <span class="code_highlight">-k -V</span> xcodebuild 163*67e74705SXin Li</pre> 164*67e74705SXin Li 165*67e74705SXin Li<p>Here is a subset of useful options:</p> 166*67e74705SXin Li 167*67e74705SXin Li<table class="options"> 168*67e74705SXin Li<colgroup><col class="option"><col class="description"></colgroup> 169*67e74705SXin Li<thead><tr><td>Option</td><td>Description</td></tr></thead> 170*67e74705SXin Li 171*67e74705SXin Li<tr><td><b>-o</b></td><td>Target directory for HTML report files. Subdirectories 172*67e74705SXin Liwill be created as needed to represent separate "runs" of the analyzer. If this 173*67e74705SXin Lioption is not specified, a directory is created in <tt>/tmp</tt> to store the 174*67e74705SXin Lireports.</td></tr> 175*67e74705SXin Li 176*67e74705SXin Li<tr><td><b>-h</b><br><i>(or no arguments)</i></td><td>Display all 177*67e74705SXin Li<tt>scan-build</tt> options.</td></tr> 178*67e74705SXin Li 179*67e74705SXin Li<tr><td><b>-k</b><br><b>--keep-going</b></td><td>Add a "keep on 180*67e74705SXin Ligoing" option to the specified build command. <p>This option currently supports 181*67e74705SXin Li<tt>make</tt> and <tt>xcodebuild</tt>.</p> <p>This is a convenience option; one 182*67e74705SXin Lican specify this behavior directly using build options.</p></td></tr> 183*67e74705SXin Li 184*67e74705SXin Li<tr><td><b>-v</b></td><td>Verbose output from scan-build and the analyzer. <b>A 185*67e74705SXin Lisecond and third "-v" increases verbosity</b>, and is useful for filing bug 186*67e74705SXin Lireports against the analyzer.</td></tr> 187*67e74705SXin Li 188*67e74705SXin Li<tr><td><b>-V</b></td><td>View analysis results in a web browser when the build 189*67e74705SXin Licommand completes.</td></tr> 190*67e74705SXin Li 191*67e74705SXin Li<tr><td><b>--use-analyzer Xcode</b><br><i>or</i><br> 192*67e74705SXin Li<b>--use-analyzer [path to clang]</b></td><td><tt>scan-build</tt> uses the 193*67e74705SXin Li'clang' executable relative to itself for static analysis. One can override this 194*67e74705SXin Libehavior with this option by using the 'clang' packaged with Xcode (on OS X) or 195*67e74705SXin Lifrom the PATH.</p></td></tr> </table> 196*67e74705SXin Li 197*67e74705SXin Li<p>A complete list of options can be obtained by running <tt>scan-build</tt> 198*67e74705SXin Liwith no arguments.</p> 199*67e74705SXin Li 200*67e74705SXin Li<h3 id="scanbuild_output">Output of scan-build</h3> 201*67e74705SXin Li 202*67e74705SXin Li<p> 203*67e74705SXin LiThe output of scan-build is a set of HTML files, each one which represents a 204*67e74705SXin Liseparate bug report. A single <tt>index.html</tt> file is generated for 205*67e74705SXin Lisurveying all of the bugs. You can then just open <tt>index.html</tt> in a web 206*67e74705SXin Librowser to view the bug reports. 207*67e74705SXin Li</p> 208*67e74705SXin Li 209*67e74705SXin Li<p> 210*67e74705SXin LiWhere the HTML files are generated is specified with a <b>-o</b> option to 211*67e74705SXin Li<tt>scan-build</tt>. If <b>-o</b> isn't specified, a directory in <tt>/tmp</tt> 212*67e74705SXin Liis created to store the files (<tt>scan-build</tt> will print a message telling 213*67e74705SXin Liyou where they are). If you want to view the reports immediately after the build 214*67e74705SXin Licompletes, pass <b>-V</b> to <tt>scan-build</tt>. 215*67e74705SXin Li</p> 216*67e74705SXin Li 217*67e74705SXin Li 218*67e74705SXin Li<h2 id="recommendedguidelines">Recommended Usage Guidelines</h2> 219*67e74705SXin Li 220*67e74705SXin Li<p>This section describes a few recommendations with running the analyzer.</p> 221*67e74705SXin Li 222*67e74705SXin Li<h3 id="recommended_debug">ALWAYS analyze a project in its "debug" configuration</h3> 223*67e74705SXin Li 224*67e74705SXin Li<p>Most projects can be built in a "debug" mode that enables assertions. 225*67e74705SXin LiAssertions are picked up by the static analyzer to prune infeasible paths, which 226*67e74705SXin Liin some cases can greatly reduce the number of false positives (bogus error 227*67e74705SXin Lireports) emitted by the tool.</p> 228*67e74705SXin Li 229*67e74705SXin Li<p>Another option is to use <tt>--force-analyze-debug-code</tt> flag of 230*67e74705SXin Li<b>scan-build</b> tool which would enable assertions automatically.</p> 231*67e74705SXin Li 232*67e74705SXin Li<h3 id="recommend_verbose">Use verbose output when debugging scan-build</h3> 233*67e74705SXin Li 234*67e74705SXin Li<p><tt>scan-build</tt> takes a <b>-v</b> option to emit verbose output about 235*67e74705SXin Liwhat it's doing; two <b>-v</b> options emit more information. Redirecting the 236*67e74705SXin Lioutput of <tt>scan-build</tt> to a text file (make sure to redirect standard 237*67e74705SXin Lierror) is useful for filing bug reports against <tt>scan-build</tt> or the 238*67e74705SXin Lianalyzer, as we can see the exact options (and files) passed to the analyzer. 239*67e74705SXin LiFor more comprehensible logs, don't perform a parallel build.</p> 240*67e74705SXin Li 241*67e74705SXin Li<h3 id="recommended_autoconf">Run './configure' through scan-build</h3> 242*67e74705SXin Li 243*67e74705SXin Li<p>If an analyzed project uses an autoconf generated <tt>configure</tt> script, 244*67e74705SXin Liyou will probably need to run <tt>configure</tt> script through 245*67e74705SXin Li<tt>scan-build</tt> in order to analyze the project.</p> 246*67e74705SXin Li 247*67e74705SXin Li<p><b>Example</b></p> 248*67e74705SXin Li 249*67e74705SXin Li<pre class="code_example"> 250*67e74705SXin Li$ scan-build ./configure 251*67e74705SXin Li$ scan-build make 252*67e74705SXin Li</pre> 253*67e74705SXin Li 254*67e74705SXin Li<p>The reason <tt>configure</tt> also needs to be run through 255*67e74705SXin Li<tt>scan-build</tt> is because <tt>scan-build</tt> scans your source files by 256*67e74705SXin Li<i>interposing</i> on the compiler. This interposition is currently done by 257*67e74705SXin Li<tt>scan-build</tt> temporarily setting the environment variable <tt>CC</tt> to 258*67e74705SXin Li<tt>ccc-analyzer</tt>. The program <tt>ccc-analyzer</tt> acts like a fake 259*67e74705SXin Licompiler, forwarding its command line arguments over to the compiler to perform 260*67e74705SXin Liregular compilation and <tt>clang</tt> to perform static analysis.</p> 261*67e74705SXin Li 262*67e74705SXin Li<p>Running <tt>configure</tt> typically generates makefiles that have hardwired 263*67e74705SXin Lipaths to the compiler, and by running <tt>configure</tt> through 264*67e74705SXin Li<tt>scan-build</tt> that path is set to <tt>ccc-analyzer</tt>.</p> 265*67e74705SXin Li 266*67e74705SXin Li<!-- 267*67e74705SXin Li<h2 id="Debugging">Debugging the Analyzer</h2> 268*67e74705SXin Li 269*67e74705SXin Li<p>This section provides information on debugging the analyzer, and troubleshooting 270*67e74705SXin Liit when you have problems analyzing a particular project.</p> 271*67e74705SXin Li 272*67e74705SXin Li<h3>How it Works</h3> 273*67e74705SXin Li 274*67e74705SXin Li<p>To analyze a project, <tt>scan-build</tt> simply sets the environment variable 275*67e74705SXin Li<tt>CC</tt> to the full path to <tt>ccc-analyzer</tt>. It also sets a few other 276*67e74705SXin Lienvironment variables to communicate to <tt>ccc-analyzer</tt> where to dump HTML 277*67e74705SXin Lireport files.</p> 278*67e74705SXin Li 279*67e74705SXin Li<p>Some Makefiles (or equivalent project files) hardcode the compiler; for such 280*67e74705SXin Liprojects simply overriding <tt>CC</tt> won't cause <tt>ccc-analyzer</tt> to be 281*67e74705SXin Licalled. This will cause the compiled code <b>to not be analyzed.</b></p> If you 282*67e74705SXin Lifind that your code isn't being analyzed, check to see if <tt>CC</tt> is 283*67e74705SXin Lihardcoded. If this is the case, you can hardcode it instead to the <b>full 284*67e74705SXin Lipath</b> to <tt>ccc-analyzer</tt>.</p> 285*67e74705SXin Li 286*67e74705SXin Li<p>When applicable, you can also run <tt>./configure</tt> for a project through 287*67e74705SXin Li<tt>scan-build</tt> so that configure sets up the location of <tt>CC</tt> based 288*67e74705SXin Lion the environment passed in from <tt>scan-build</tt>: 289*67e74705SXin Li 290*67e74705SXin Li<pre> 291*67e74705SXin Li $ scan-build <b>./configure</b> 292*67e74705SXin Li</pre> 293*67e74705SXin Li 294*67e74705SXin Li<p><tt>scan-build</tt> has special knowledge about <tt>configure</tt>, so it in 295*67e74705SXin Limost cases will not actually analyze the configure tests run by 296*67e74705SXin Li<tt>configure</tt>.</p> 297*67e74705SXin Li 298*67e74705SXin Li<p>Under the hood, <tt>ccc-analyzer</tt> directly invokes <tt>gcc</tt> to 299*67e74705SXin Licompile the actual code in addition to running the analyzer (which occurs by it 300*67e74705SXin Licalling <tt>clang</tt>). <tt>ccc-analyzer</tt> tries to correctly forward all 301*67e74705SXin Lithe arguments over to <tt>gcc</tt>, but this may not work perfectly (please 302*67e74705SXin Lireport bugs of this kind). 303*67e74705SXin Li --> 304*67e74705SXin Li 305*67e74705SXin Li<h2 id="iphone">Analyzing iPhone Projects</h2> 306*67e74705SXin Li 307*67e74705SXin Li<p>Conceptually Xcode projects for iPhone applications are nearly the same as 308*67e74705SXin Litheir cousins for desktop applications. <b>scan-build</b> can analyze these 309*67e74705SXin Liprojects as well, but users often encounter problems with just building their 310*67e74705SXin LiiPhone projects from the command line because there are a few extra preparative 311*67e74705SXin Listeps they need to take (e.g., setup code signing).</p> 312*67e74705SXin Li 313*67e74705SXin Li<h3>Recommendation: use "Build and Analyze"</h3> 314*67e74705SXin Li 315*67e74705SXin Li<p>The absolute easiest way to analyze iPhone projects is to use the 316*67e74705SXin Li<a href="https://developer.apple.com/library/ios/recipes/xcode_help-source_editor/chapters/Analyze.html#//apple_ref/doc/uid/TP40009975-CH4-SW1"><i>Analyze</i> 317*67e74705SXin Lifeature in Xcode</a> (which is based on the Clang Static Analyzer). There a 318*67e74705SXin Liuser can analyze their project right from a menu without most of the setup 319*67e74705SXin Lidescribed later.</p> 320*67e74705SXin Li 321*67e74705SXin Li<p><a href="/xcode.html">Instructions are available</a> on this 322*67e74705SXin Liwebsite on how to use open source builds of the analyzer as a replacement for 323*67e74705SXin Lithe one bundled with Xcode.</p> 324*67e74705SXin Li 325*67e74705SXin Li<h3>Using scan-build directly</h3> 326*67e74705SXin Li 327*67e74705SXin Li<p>If you wish to use <b>scan-build</b> with your iPhone project, keep the 328*67e74705SXin Lifollowing things in mind:</p> 329*67e74705SXin Li 330*67e74705SXin Li<ul> 331*67e74705SXin Li <li>Analyze your project in the <tt>Debug</tt> configuration, either by setting 332*67e74705SXin Lithis as your configuration with Xcode or by passing <tt>-configuration 333*67e74705SXin LiDebug</tt> to <tt>xcodebuild</tt>.</li> 334*67e74705SXin Li <li>Analyze your project using the <tt>Simulator</tt> as your base SDK. It is 335*67e74705SXin Lipossible to analyze your code when targeting the device, but this is much 336*67e74705SXin Lieasier to do when using Xcode's <i>Build and Analyze</i> feature.</li> 337*67e74705SXin Li <li>Check that your code signing SDK is set to the simulator SDK as well, and make sure this option is set to <tt>Don't Code Sign</tt>.</li> 338*67e74705SXin Li</ul> 339*67e74705SXin Li 340*67e74705SXin Li<p>Note that you can most of this without actually modifying your project. For 341*67e74705SXin Liexample, if your application targets iPhoneOS 2.2, you could run 342*67e74705SXin Li<b>scan-build</b> in the following manner from the command line:</p> 343*67e74705SXin Li 344*67e74705SXin Li<pre class="code_example"> 345*67e74705SXin Li$ scan-build xcodebuild -configuration Debug -sdk iphonesimulator2.2 346*67e74705SXin Li</pre> 347*67e74705SXin Li 348*67e74705SXin LiAlternatively, if your application targets iPhoneOS 3.0: 349*67e74705SXin Li 350*67e74705SXin Li<pre class="code_example"> 351*67e74705SXin Li$ scan-build xcodebuild -configuration Debug -sdk iphonesimulator3.0 352*67e74705SXin Li</pre> 353*67e74705SXin Li 354*67e74705SXin Li<h3>Gotcha: using the right compiler</h3> 355*67e74705SXin Li 356*67e74705SXin Li<p>Recall that <b>scan-build</b> analyzes your project by using a compiler to 357*67e74705SXin Licompile the project and <tt>clang</tt> to analyze your project. The script uses 358*67e74705SXin Lisimple heuristics to determine which compiler should be used (it defaults to 359*67e74705SXin Li<tt>clang</tt> on Darwin and <tt>gcc</tt> on other platforms). When analyzing 360*67e74705SXin LiiPhone projects, <b>scan-build</b> may pick the wrong compiler than the one 361*67e74705SXin LiXcode would use to build your project. For example, this could be because 362*67e74705SXin Limultiple versions of a compiler may be installed on your system, especially if 363*67e74705SXin Liyou are developing for the iPhone.</p> 364*67e74705SXin Li 365*67e74705SXin Li<p>When compiling your application to run on the simulator, it is important that <b>scan-build</b> 366*67e74705SXin Lifinds the correct version of <tt>gcc/clang</tt>. Otherwise, you may see strange build 367*67e74705SXin Lierrors that only happen when you run <tt>scan-build</tt>. 368*67e74705SXin Li 369*67e74705SXin Li<p><b>scan-build</b> provides the <tt>--use-cc</tt> and <tt>--use-c++</tt> 370*67e74705SXin Lioptions to hardwire which compiler scan-build should use for building your code. 371*67e74705SXin LiNote that although you are chiefly interested in analyzing your project, keep in 372*67e74705SXin Limind that running the analyzer is intimately tied to the build, and not being 373*67e74705SXin Liable to compile your code means it won't get fully analyzed (if at all).</p> 374*67e74705SXin Li 375*67e74705SXin Li<p>If you aren't certain which compiler Xcode uses to build your project, try 376*67e74705SXin Lijust running <tt>xcodebuild</tt> (without <b>scan-build</b>). You should see the 377*67e74705SXin Lifull path to the compiler that Xcode is using, and use that as an argument to 378*67e74705SXin Li<tt>--use-cc</tt>.</p> 379*67e74705SXin Li 380*67e74705SXin Li</div> 381*67e74705SXin Li</div> 382*67e74705SXin Li</body> 383*67e74705SXin Li</html> 384*67e74705SXin Li 385