List of all available Websheets
Viewing cpp/cs102/practice9/compiling by redekopp@usc.edu. You have unsaved changes. Log in above to create, edit, preview and publish Websheets.
Property | Value |
---|---|
Description html markup shown to student | <p>Let's practice complining code using the Linux terminal from the Vocareum virtual machine web interface.</p> <p>Follow these steps, then copy the output of the compiler into the box below.</p> <ol> <li>Login to Vocareum and start Lab 11. Start the compilation exercise.</li> <li>Create a new file using the "New".."File" button in the upper left and name it <tt>lab9.cpp</tt></li> <li>Select the file in the left pane and then copy the following into the editor window</li> <pre><code> #include <iostream> using namespace std; int main() { int didNotNeed; int flse = 0; char cool = 'c'; if (cool = 'c') cout << "This code is perfect" << endl; if (~flse) cout << 2/0; return 'y'; }</code></pre></li> <li>In the terminal window at the bottom, type <tt>ls</tt>. You should see a listing of the files in the <tt>work</tt> directory which for now is just <tt>lab9.cpp</tt></li> <li>Compile it using the g++ command with -Wall enabled: <tt>g++ -Wall lab9.cpp</tt></li> <li>Type <tt>ls</tt> in the terminal window again. Now you should see two files in the folder: <tt>a.out lab9.cpp</tt>. <strong><tt>a.out</tt></strong> is the default name given to the program the compiler creates.</strong> This name is not very descriptive. Let's have it use a different name for the executable program.</li> <li>Recompile the program adding the <tt>-o progname</tt> option. Type: <tt>g++ -Wall lab9.cpp -o lab9</tt>.<br> <strong>Note the warnings that are generated and mark the ones that are listed as proof you were able to do this step successfully.</strong></li> <li>Type <tt>ls</tt> in the terminal window again. Now you should see three files in the folder: <tt>a.out lab9 lab9.cpp</tt>. <tt>lab9</tt> is now the executable program that you can execute. </li> <li>To run the program, type <tt>./lab9</tt> at the terminal command line.</li> This program should start running but then crash with the message <tt>Floating point exception (code dumped)</tt> due to the divide by 0 error.</li> </ol> <p> To summarize, the general flow of compiling and running your program is:</p> <ol> <li>Write your code in an editor and save it</li> <li>Compile your program using a line such as: <tt>g++ -Wall your-file.cpp -o exec-prog-name</tt>. Replace <tt>your-file.cpp</tt> and <tt>exec-prog-name</tt> with the name of your file and desired executable program name.</li> <li>Run the program by typing <tt>./exec-prog-name</tt> where you replace the <tt>exec-prog-name</tt> with your program name from above.</li> <li>If the program works as expected, you are done.</li> <li>If the program has a problem go back to the start and change your code and go through all these steps again.</li> </ol> |
Engine | |
Choices json list of string, bool pairs e.g. [["good", true], ["bad", false]] | [["warning: g++ used instead of clang; recommened recompiling with f- OS X flag [-WMacintosh]", null], ["warning: suggest parentheses around assignment used as truth value [-Wall]", null], ["warning: assignment operator used instead of equality operator? [-Wshadow]", null], ["warning: division by zero [-Wdiv-by-zero]", null], ["warning: unused variable \u2018didNotNeed\u2019 [-Wunused-variable]", null], ["warning: return type is int, but implicit cast from char is present [-Wconversion]", null], ["warning: bitwise not used on boolean type; may cause errors on systems without single-bit registers [-Wbitwise]", null], ["warning: suggest parentheses around assignment used as truth value [-Wparentheses]", null], ["warning: non-reserved keyword 'flse' used; did you mean 'false'? [-Wboolean]", null]] |
Note: problems are open-source by default (see 'Public permissions'). Assumed license for open problems is Creative Commons 4.0 Attribution-ShareAlike unless specified in 'Remarks'.