{"id":4553,"date":"2021-01-16T00:01:47","date_gmt":"2021-01-16T08:01:47","guid":{"rendered":"https:\/\/c-for-dummies.com\/blog\/?p=4553"},"modified":"2021-01-09T16:17:24","modified_gmt":"2021-01-10T00:17:24","slug":"compiler-options-in-codeblocks","status":"publish","type":"post","link":"https:\/\/c-for-dummies.com\/blog\/?p=4553","title":{"rendered":"Compiler Options in Code::Blocks"},"content":{"rendered":"<p>Like all IDEs, Code::Blocks is effectively a front for the <em>clang<\/em>, <em>minGW<\/em>, or <em>gcc<\/em> compiler lurking somewhere under its skin. While you don&#8217;t use these command line tools directly, you can control their options and settings from within the IDE.<br \/>\n<!--more--><br \/>\nCompiler options are set in the Compiler Settings dialog box, a busy place shown in Figure 1. Place a checkmark in the box to activate an option. The option&#8217;s related command line switch (some of which are covered in <a href=\"https:\/\/c-for-dummies.com\/blog\/?p=4551\">last week&#8217;s Lesson<\/a>) is listed for each option.<\/p>\n<div id=\"attachment_4564\" style=\"width: 310px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/c-for-dummies.com\/blog\/wp-content\/uploads\/2021\/01\/0116-Figure1.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-4564\" src=\"https:\/\/c-for-dummies.com\/blog\/wp-content\/uploads\/2021\/01\/0116-Figure1-300x294.png\" alt=\"Global Compiler Settings\" width=\"300\" height=\"294\" class=\"size-medium wp-image-4564\" srcset=\"https:\/\/c-for-dummies.com\/blog\/wp-content\/uploads\/2021\/01\/0116-Figure1-300x294.png 300w, https:\/\/c-for-dummies.com\/blog\/wp-content\/uploads\/2021\/01\/0116-Figure1-306x300.png 306w, https:\/\/c-for-dummies.com\/blog\/wp-content\/uploads\/2021\/01\/0116-Figure1.png 756w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><p id=\"caption-attachment-4564\" class=\"wp-caption-text\">Figure 1. Setting compiler options in Code::Blocks (click to embiggen).<\/p><\/div>\n<p>To summon the Compiler Settings dialog box, choose Settings, Compiler in Code::Blocks. The Global Compiler Settings screen is chosen, Compiler Settings tab, Compiler Flags sub-tab set as shown in Figure 1.<\/p>\n<p>If you click the Other Compiler Options tab, you can enter switches manually. Or you can create a new entry on the Compiler Flags sub-tab by right-clicking.<\/p>\n<p>A similar dialog box is provided for Code::Blocks projects. Unlike the Compiler Settings dialog box, the Project Build Options dialog box applies only to the current project. The settings and dialog box are pretty much identical; summon the dialog box by choosing Project, Build Options.<\/p>\n<p>If you plan on debugging your code in Code::Blocks, ensure that the project is created with a debugging build. This configuration automatically applies the <code>-g<\/code> switch used at the command prompt.<\/p>\n<p>To compile a project without linking, choose Build, Compile Current File. This choice replaces the <code>-c<\/code> switch at the command prompt.<\/p>\n<p>The only complex settings required in Code::Blocks are choosing specific directories for libraries and header files. At the command prompt, you use switches. In Code::Blocks, these options are set in the Linker Settings tab, found in the Compiler Settings dialog box (shown in Figure 1).<\/p>\n<p>For example, to set the location of a library you&#8217;ve downloaded, choose either Project, Build Options or you can choose Settings, Compiler.<\/p>\n<p>Click Add button.<\/p>\n<p>If you know the library&#8217;s path (folder), type it in, otherwise do what I do and click the Folder button to browse for the library, as illustrated in Figure 2.<\/p>\n<div id=\"attachment_4565\" style=\"width: 310px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/c-for-dummies.com\/blog\/wp-content\/uploads\/2021\/01\/0116-Figure2.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-4565\" src=\"https:\/\/c-for-dummies.com\/blog\/wp-content\/uploads\/2021\/01\/0116-Figure2-300x184.png\" alt=\"A dialog box\" width=\"300\" height=\"184\" class=\"size-medium wp-image-4565\" srcset=\"https:\/\/c-for-dummies.com\/blog\/wp-content\/uploads\/2021\/01\/0116-Figure2-300x184.png 300w, https:\/\/c-for-dummies.com\/blog\/wp-content\/uploads\/2021\/01\/0116-Figure2-1024x628.png 1024w, https:\/\/c-for-dummies.com\/blog\/wp-content\/uploads\/2021\/01\/0116-Figure2-768x471.png 768w, https:\/\/c-for-dummies.com\/blog\/wp-content\/uploads\/2021\/01\/0116-Figure2-489x300.png 489w, https:\/\/c-for-dummies.com\/blog\/wp-content\/uploads\/2021\/01\/0116-Figure2.png 1115w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><p id=\"caption-attachment-4565\" class=\"wp-caption-text\">Figure 2. Setting the location for a library file (click to embiggen).<\/p><\/div>\n<p>Select the library and click Open.<\/p>\n<p>Click OK in the Add Library dialog box.<\/p>\n<p>Click OK.<\/p>\n<p>The library path is added so that the compiler knows where to find it. Likewise, you can select a folder for header files: In the same dialog box, click the Search Directories tab. In the Compiler sub-tab, click the Add button to set the location where the compiler can hunt down header files.<\/p>\n<p>Again, all these options and settings are translated into command line switches. A build time, Code::Blocks ventures out to the command prompt to run the compiler, all options and switches set per your specifications. For larger programs, this feature is a convenience. For smaller programs, like my demo code, you may see why I prefer the brevity of the command prompt.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>C compiler switches can also be set from within an IDE, providing you know where the options are hidden. <a href=\"https:\/\/c-for-dummies.com\/blog\/?p=4553\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[],"class_list":["post-4553","post","type-post","status-publish","format-standard","hentry","category-main"],"_links":{"self":[{"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/4553","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4553"}],"version-history":[{"count":4,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/4553\/revisions"}],"predecessor-version":[{"id":4579,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/4553\/revisions\/4579"}],"wp:attachment":[{"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4553"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4553"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4553"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}