A quick hello to shells, C++ and makefiles.
Below are some useful shell commands that you may need for today's lab:
ls :list files and directories in the current directory mkdir XXX :make a new directory called XXX cd XXX :move into sub-directory XXX cd :cd by itself takes you back to your home directory. cd .. :go up one directory svn checkout https://..... YYY :Checkout project to YYY directory svn commit -m 'message' :Commit changes in the current directory svn help
For example, the following will create a directory "red" on your machine and it will contain a copy of all the files and directories that are stored on the subversion server's 'luckydog' directory.
svn checkout https://blah.com/abc/luckydog red
Getting started:
svn checkout https://subversion.ews.illinois.edu/svn/sp17-cs125/YOURNETID/Midterm2BonusBe sure to use your own netid and make sure there are no extra spaces. Watch out for upper/lowercase.
cd Midterm2Bonus (type "cd Midterm2" then press tab to autocomplete) ls
g++ -c -g -O0 -Wall hello.cpp
link all of the libraries and binary .o files into a single executable file
This is the command to link all libraries and .o files
g++ -o exec file1.o file2.o file3.o -lmIn our case it would be
g++ -o hello hello.o -lm
./hello
This MP introduces you to C++, compilers and makefiles, things you'll be using in CS225. In CS125, Eclipse compiled your java source files automatically. In CS225, you'll need to run the C++ compiler yourself.
C and C++ programmers often use 'make' to build the software. For example, the linux kernel is compiled by typing 'make'. You specify the build rules (dependencies) in a 'Makefile'. 'make' checks the existence and modification times of files, compiling only when necessary. Type 'make' a few times, and if you haven't made any changes to any source files, then make will not recompile them. On some systems it will report:
make: Nothing to be done for `all'.
By the way, 'make' is a very general purpose tool. You can specify how a specific output file (or file extension) depends on an input file. If you update a file, or add new files, make will automatically recreate the output files, assuming you've set the rules correctly. For example, I've used it to generate thumbnails of recently added jpgs.
Remember, to see your changes you need to:
Now you'll be changing hello.cpp and you'll need to re-compile. Before we do that, let's examine how to compile the code using 'make'.
svn commit -m 'blah blah'
make ./hello
Obviously, this is a very brief introduction to some very powerful tools and concepts. Google and lab assistants are your friends if you'd like to know more!
If you have any spare time you could try running your c++ program using the debugger:
Type: gdb hello l break 10 print mesg run continue quit ----------------------- #include#include using std::string; using std::cout; using std::endl; int main() { cout << "Hey,"; string mesg = "this my first C++ program"; mesg += "!"; cout << mesg << endl; for(int i=0; i<10; i++) { cout << i*i; cout << endl; } return 0; }