<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>compilation | Learn C Games Programming Blog</title>
	<atom:link href="https://learncgames.com/tag/compilation/feed/" rel="self" type="application/rss+xml" />
	<link>https://learncgames.com</link>
	<description>A blog about C, programming games and my ebook(s).</description>
	<lastBuildDate>Sun, 04 Dec 2022 12:11:13 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>

<image>
	<url>https://learncgames.com/wp-content/uploads/2020/03/cropped-favicon-32x32.png</url>
	<title>compilation | Learn C Games Programming Blog</title>
	<link>https://learncgames.com</link>
	<width>32</width>
	<height>32</height>
</image> 
<site xmlns="com-wordpress:feed-additions:1">181446779</site>	<item>
		<title>How to Configure Visual Studio Code for C/C++ development</title>
		<link>https://learncgames.com/how-to-configure-visual-studio-code-for-c-c-development/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=how-to-configure-visual-studio-code-for-c-c-development</link>
		
		<dc:creator><![CDATA[David]]></dc:creator>
		<pubDate>Mon, 05 Dec 2022 00:00:11 +0000</pubDate>
				<category><![CDATA[C]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[Visual Studio Code]]></category>
		<category><![CDATA[compilation]]></category>
		<category><![CDATA[configuration]]></category>
		<guid isPermaLink="false">https://learncgames.com/?p=3111</guid>

					<description><![CDATA[<p>When I first started with VS Code on Linux, I found the C/C++ configuration somewhat confusing.  I blundered through, wasted a bit of time and got there in the end. After a gap of a couple of years I did the same again recently on Raspberry Pi. It&#8217;s clearer in my mind now so I [&#8230;]</p>
The post <a href="https://learncgames.com/how-to-configure-visual-studio-code-for-c-c-development/">How to Configure Visual Studio Code for C/C++ development</a> first appeared on <a href="https://learncgames.com">Learn C Games Programming Blog</a>.]]></description>
										<content:encoded><![CDATA[<p><img decoding="async" class="alignleft size-full wp-image-3113" src="https://learncgames.com/wp-content/uploads/2022/12/vscode-extensions.png" alt="VS Code C/C++ extension" width="254" height="68" srcset="https://learncgames.com/wp-content/uploads/2022/12/vscode-extensions.png 254w, https://learncgames.com/wp-content/uploads/2022/12/vscode-extensions-250x68.png 250w" sizes="(max-width: 254px) 100vw, 254px" />When I first started with VS Code on Linux, I found the C/C++ configuration somewhat confusing.  I blundered through, wasted a bit of time and got there in the end. After a gap of a couple of years I did the same again recently on Raspberry Pi. It&#8217;s clearer in my mind now so I thought I&#8217;d explain it here. This works for Ubuntu, Raspberry Pi OS and should for most other Linuxes. (<em>Not that I&#8217;ve tried them all&#8230;</em>)</p>
<p>We&#8217;ll start with you having already installed Clang (<em>or GCC</em>) and VS Code, and the C/C++ extension for VS Code (shown above). So make sure those are all done.</p>
<p>Start by defining a Folder for VS Code. VS code doesn&#8217;t use projects but it manages everything relative to the currently defined Folder.  It&#8217;ll ask you to open a folder initially. That&#8217;s where your source code etc will go. I created a folder called examples under my home folder and used that.</p>
<p>To compile anything C/C++ you also need two json files. These files are</p>
<ul>
<li>tasks.json</li>
<li>c_cpp_properties.json</li>
</ul>
<p>They are held in a hidden folder called .vscode in your current folder. Press F1 and you&#8217;ll see a popup menu. Type in C/C++ and you&#8217;ll see all the C/C++ items. Select <strong>C/C++: Edit Configurations (JSON).</strong> It&#8217;s highlighted below.</p>
<p><img fetchpriority="high" decoding="async" class="alignleft wp-image-3114 size-full" src="https://learncgames.com/wp-content/uploads/2022/12/cppconfigurations.png" alt="Vs Copde C++ menu" width="615" height="340" srcset="https://learncgames.com/wp-content/uploads/2022/12/cppconfigurations.png 615w, https://learncgames.com/wp-content/uploads/2022/12/cppconfigurations-300x166.png 300w" sizes="(max-width: 615px) 100vw, 615px" /></p>
<p>Now if you click that, and look in the folder examples you&#8217;ll see nothing but if you know how to view hidden files using the files utility (as shown below). Then you&#8217;ll see the folder <strong>.vscode</strong>.  On Raspberry Pi the file explorer always shows hidden files.</p>
<p><img decoding="async" class="alignleft size-full wp-image-3115" src="https://learncgames.com/wp-content/uploads/2022/12/showHiddenFiles.png" alt="Show hidden files in files utility" width="218" height="352" srcset="https://learncgames.com/wp-content/uploads/2022/12/showHiddenFiles.png 218w, https://learncgames.com/wp-content/uploads/2022/12/showHiddenFiles-186x300.png 186w" sizes="(max-width: 218px) 100vw, 218px" /> Now look in that folder and you&#8217;ll see <strong>c_cpp_properties.json</strong>.</p>
<p>Next we want <strong>tasks.json</strong>. On the Terminal menu, click the bottom item which is <em>Configure Default Build Task</em></p>
<p>It&#8217;ll ask you to select the <strong>clang  build active task</strong> so click that and voila you now have <strong>tasks.json</strong> open in the editor.</p>
<p><img loading="lazy" decoding="async" class="alignleft size-full wp-image-3117" src="https://learncgames.com/wp-content/uploads/2022/12/configure-default-build-task.png" alt="Vs Code Configure Default Build Task" width="361" height="343" srcset="https://learncgames.com/wp-content/uploads/2022/12/configure-default-build-task.png 361w, https://learncgames.com/wp-content/uploads/2022/12/configure-default-build-task-300x285.png 300w" sizes="auto, (max-width: 361px) 100vw, 361px" /></p>
<p><img loading="lazy" decoding="async" class="alignleft size-full wp-image-3119" src="https://learncgames.com/wp-content/uploads/2022/12/build-active-file.png" alt="Build Active File" width="592" height="79" srcset="https://learncgames.com/wp-content/uploads/2022/12/build-active-file.png 592w, https://learncgames.com/wp-content/uploads/2022/12/build-active-file-300x40.png 300w" sizes="auto, (max-width: 592px) 100vw, 592px" /></p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>Now I&#8217;ve created the standard hello world file in the file hw.c.</p>
<pre><code class="language-c" data-line="">#include &lt;stdio.h&gt;

int main() {
  printf(&quot;Hello world\n&quot;);
  return 0;
}</code></pre>
<p>So just do <em>Terminal/Run Build Task</em> and it will have clang compile the currently opened file. If you get terminal failed to launch (exit code: -1) then it&#8217;s likely that your hello world source file was not the currently opened file in the editor. You can see which file is open because its tab is brightest.</p>
<p>Note that hw.c is brighter than tasks.json on the left. On the right, the open file is tasks.json and its tab is brighter.</p>
<p><img loading="lazy" decoding="async" class="alignleft size-full wp-image-3126" src="https://learncgames.com/wp-content/uploads/2022/12/open-file.png" alt="Open file in VS Code" width="330" height="201" srcset="https://learncgames.com/wp-content/uploads/2022/12/open-file.png 330w, https://learncgames.com/wp-content/uploads/2022/12/open-file-300x183.png 300w" sizes="auto, (max-width: 330px) 100vw, 330px" /></p>
<h3><img loading="lazy" decoding="async" class="alignleft size-full wp-image-3127" src="https://learncgames.com/wp-content/uploads/2022/12/open-tasks.json.png" alt="Tasks.json is open" width="526" height="185" srcset="https://learncgames.com/wp-content/uploads/2022/12/open-tasks.json.png 526w, https://learncgames.com/wp-content/uploads/2022/12/open-tasks.json-300x106.png 300w" sizes="auto, (max-width: 526px) 100vw, 526px" /></h3>
<h3></h3>
<h3></h3>
<h3></h3>
<h3></h3>
<h3></h3>
<h3>So what are the json files for?</h3>
<p>The c_cpp_properties.json lets you specify include file paths.  For instance if you have the SDL files installed, the include files are in <strong>/usr/include/SDL2</strong></p>
<p><img loading="lazy" decoding="async" class="alignleft size-full wp-image-3129" src="https://learncgames.com/wp-content/uploads/2022/12/sdl2-include-files.png" alt="SDL2 include files" width="551" height="247" srcset="https://learncgames.com/wp-content/uploads/2022/12/sdl2-include-files.png 551w, https://learncgames.com/wp-content/uploads/2022/12/sdl2-include-files-300x134.png 300w" sizes="auto, (max-width: 551px) 100vw, 551px" /></p>
<p>Note you can install SDL on linux by <a title="Link to how to install SDL on Linux" href="https://learncgames.com/tutorials/how-to-install-sdl-on-linux/" target="_blank" rel="noopener">following these instructions</a>.</p>
<p>The tasks.json file lets you specify which files are to be included and also linked.</p>
<p>Here I&#8217;ve just shown the args section from a <strong>tasks.json</strong> used to build SDL2 games.</p>
<pre><code class="language-json" data-line="">	&quot;args&quot;: [
		&quot;-g&quot;,
		&quot;${file}&quot;,
		&quot;${workspaceFolder}/hr_time.c&quot;,
		&quot;-o&quot;,
		&quot;${fileDirname}/${fileBasenameNoExtension}&quot;,
		&quot;-lSDL2&quot;,
		&quot;-lSDL2_image&quot;,
		&quot;-lSDL2_mixer&quot;,
		&quot;-lm&quot;
	],</code></pre>
<p>The -g option includes files. The ${file} is the current opened file and {workspaceFolder{} specifies the current folder where the file hr_time.c (used for timing). The -l is for linking files and links SDL2, SDL2_image and SDL2_mixer.  The last <strong>-lm</strong> links math(s) code; technically the -l{name} flag tells the linker to link against lib{name}. So -lm links against libm, the c math library.</p>The post <a href="https://learncgames.com/how-to-configure-visual-studio-code-for-c-c-development/">How to Configure Visual Studio Code for C/C++ development</a> first appeared on <a href="https://learncgames.com">Learn C Games Programming Blog</a>.]]></content:encoded>
					
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">3111</post-id>	</item>
	</channel>
</rss>
