<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Command Line Development | Chemeketa CS</title><link>https://computerscience.chemeketa.edu/guides/command-line-development/</link><atom:link href="https://computerscience.chemeketa.edu/guides/command-line-development/index.xml" rel="self" type="application/rss+xml"/><description>Command Line Development</description><generator>Source Themes Academic (https://sourcethemes.com/academic/)</generator><language>en-us</language><image><url>https://computerscience.chemeketa.edu/images/icon_hu_9ce158bca5f7cacc.png</url><title>Command Line Development</title><link>https://computerscience.chemeketa.edu/guides/command-line-development/</link></image><item><title>Compile and Run C++</title><link>https://computerscience.chemeketa.edu/guides/command-line-development/compile-and-run/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://computerscience.chemeketa.edu/guides/command-line-development/compile-and-run/</guid><description>&lt;p&gt;Build Chemeketa project templates with Make. You can also run the compiler yourself to
practice the complete command or diagnose a build problem.&lt;/p&gt;
&lt;h2 id="compiler-commands-by-environment"&gt;Compiler commands by environment&lt;/h2&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Environment&lt;/th&gt;
&lt;th&gt;Compiler command&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Codespaces&lt;/td&gt;
&lt;td&gt;&lt;code&gt;g++&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Windows&lt;/td&gt;
&lt;td&gt;&lt;code&gt;g++&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;macOS with the required Homebrew GCC&lt;/td&gt;
&lt;td&gt;&lt;code&gt;g++-15&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Linux&lt;/td&gt;
&lt;td&gt;&lt;code&gt;g++&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;WSL&lt;/td&gt;
&lt;td&gt;&lt;code&gt;g++&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;h2 id="compile-one-source-file"&gt;Compile one source file&lt;/h2&gt;
&lt;p&gt;Use the appropriate compiler command for your environment:&lt;/p&gt;
&lt;pre&gt;&lt;code class="language-bash"&gt;g++ -g -Wall -Wextra -std=c++20 main.cpp -o program.exe
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;On macOS, replace &lt;code&gt;g++&lt;/code&gt; with &lt;code&gt;g++-15&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Compile every &lt;code&gt;.cpp&lt;/code&gt; implementation file that belongs to the program. Do not list header
files as compiler inputs:&lt;/p&gt;
&lt;pre&gt;&lt;code class="language-bash"&gt;g++ -g -Wall -Wextra -std=c++20 main.cpp helper.cpp -o program.exe
&lt;/code&gt;&lt;/pre&gt;
&lt;h2 id="run-the-program"&gt;Run the program&lt;/h2&gt;
&lt;p&gt;Bash in Codespaces, macOS, Linux, or WSL:&lt;/p&gt;
&lt;pre&gt;&lt;code class="language-bash"&gt;./program.exe
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;PowerShell on Windows:&lt;/p&gt;
&lt;pre&gt;&lt;code class="language-powershell"&gt;.\program.exe
&lt;/code&gt;&lt;/pre&gt;
&lt;h2 id="build-a-template-with-make"&gt;Build a template with Make&lt;/h2&gt;
&lt;p&gt;From the project folder, use:&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Environment&lt;/th&gt;
&lt;th&gt;Command&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Windows&lt;/td&gt;
&lt;td&gt;&lt;code&gt;mingw32-make&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Codespaces, macOS, Linux, or WSL&lt;/td&gt;
&lt;td&gt;&lt;code&gt;make&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;Template targets include:&lt;/p&gt;
&lt;pre&gt;&lt;code class="language-bash"&gt;make program.exe
make tests.exe
make clean
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Not every template contains both executable targets. The Basic Project builds
&lt;code&gt;program.exe&lt;/code&gt;, the Unit Test Project builds &lt;code&gt;tests.exe&lt;/code&gt;, and the Combo Project builds
both.&lt;/p&gt;
&lt;p&gt;To learn how Makefile rules, prerequisites, and targets work, continue to the
&lt;a href="../makefiles/"&gt;Makefile Tutorial&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id="common-compiler-options"&gt;Common compiler options&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;-g&lt;/code&gt; includes information needed by the debugger.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;-Wall -Wextra&lt;/code&gt; enables useful warnings.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;-std=c++20&lt;/code&gt; selects the course language standard.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;-o NAME&lt;/code&gt; chooses the executable's filename.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;-I FOLDER&lt;/code&gt; adds a folder to the header search path.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;-c&lt;/code&gt; compiles without linking an executable.&lt;/li&gt;
&lt;/ul&gt;</description></item><item><title>Terminal Basics</title><link>https://computerscience.chemeketa.edu/guides/command-line-development/terminal-basics/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://computerscience.chemeketa.edu/guides/command-line-development/terminal-basics/</guid><description>&lt;p&gt;Use the terminal to run development tools by typing commands. Codespaces, macOS, Linux,
and WSL normally use a Bash-compatible shell. Native Windows development normally uses
PowerShell.&lt;/p&gt;
&lt;p&gt;Open VS Code's terminal with &lt;strong&gt;Terminal &amp;gt; New Terminal&lt;/strong&gt;. It starts in the folder open in
VS Code.&lt;/p&gt;
&lt;h2 id="navigation-quick-reference"&gt;Navigation quick reference&lt;/h2&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Goal&lt;/th&gt;
&lt;th&gt;Bash and PowerShell&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Show the current folder&lt;/td&gt;
&lt;td&gt;&lt;code&gt;pwd&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;List files&lt;/td&gt;
&lt;td&gt;&lt;code&gt;ls&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Enter a folder&lt;/td&gt;
&lt;td&gt;&lt;code&gt;cd FOLDER_NAME&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Go up one folder&lt;/td&gt;
&lt;td&gt;&lt;code&gt;cd ..&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Refer to the current folder&lt;/td&gt;
&lt;td&gt;&lt;code&gt;.&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Clear the terminal&lt;/td&gt;
&lt;td&gt;&lt;code&gt;clear&lt;/code&gt; in Bash; &lt;code&gt;Clear-Host&lt;/code&gt; in PowerShell&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;Put quotation marks around a path containing spaces:&lt;/p&gt;
&lt;pre&gt;&lt;code class="language-bash"&gt;cd &amp;quot;folder with spaces&amp;quot;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;It is easier to avoid spaces when naming programming projects.&lt;/p&gt;
&lt;h2 id="useful-terminal-features"&gt;Useful terminal features&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Press &lt;strong&gt;Tab&lt;/strong&gt; to complete a partially typed file or command.&lt;/li&gt;
&lt;li&gt;Press &lt;strong&gt;Up Arrow&lt;/strong&gt; and &lt;strong&gt;Down Arrow&lt;/strong&gt; to reuse earlier commands.&lt;/li&gt;
&lt;li&gt;Press &lt;code&gt;Ctrl+C&lt;/code&gt; to interrupt a program that is running in the terminal.&lt;/li&gt;
&lt;li&gt;Use &lt;code&gt;code .&lt;/code&gt; to open the current folder in VS Code when the &lt;code&gt;code&lt;/code&gt; command is
available.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id="platform-differences"&gt;Platform differences&lt;/h2&gt;
&lt;p&gt;Bash runs a program in the current folder with &lt;code&gt;./program.exe&lt;/code&gt;. PowerShell uses
&lt;code&gt;.\program.exe&lt;/code&gt;. Paths in Bash use &lt;code&gt;/&lt;/code&gt;; native Windows paths normally use &lt;code&gt;\&lt;/code&gt; and a
drive letter such as &lt;code&gt;C:&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Once you can navigate to a project folder, use
&lt;a href="../compile-and-run/"&gt;Compile and Run&lt;/a&gt; to build a program. Use
&lt;a href="../input-redirection/"&gt;Input Redirection&lt;/a&gt; to send a file to a program.&lt;/p&gt;</description></item></channel></rss>