Oregon State University School of Electrical Engineering and Computer Science CS 261 Recitation 1 Compiling C on UNIX Winter 2017
Outline Secure Shell Basic UNIX commands Editing text The GNU Compiler Collection (gcc) CS 261 Data Structures 2
Secure Shell Tools Mac OS X / Linux Open a terminal Type ssh [username]@[server] ssh kuleszto@flip.engr.oregonstate.edu scp [file] [username]@[server] Windows Transmit, Cyberduck, Filezilla, etc. (if you want a GUI) Putty (http://it.engineering.oregonstate.edu/accessingunix-server-using-putty-ssh) MobaXterm WinSCP (http://winscp.net/) CS 261 Data Structures 3
Putty Configuration [username]@[server] Server name Save the connection Open a saved connection CS 261 Data Structures 4
WinSCP Configuration [server] [username] Save the connection CS 261 Data Structures 5
WinSCP Usage Drag and drop to upload/download files Your computer Server CS 261 Data Structures 6
UNIX Servers @ OSU ENGR flip.engr.oregonstate.edu (RHEL 6.5) flop.engr.oregonstate.edu (RHEL 6.5) ONID shell.onid.oregonstate.edu (Debian 6.0) CS 261 Data Structures 7
Outline Secure Shell Basic UNIX commands Editing text The GNU Compiler Collection (gcc) Setting up your IDE Basic debugging CS 261 Data Structures 8
Basic UNIX Commands Command ls cd [dir name] pwd mkdir [dir name] rmdir [dir name] cp [file] [new file] mv [file] [new file] rm [file] cat [file] exit ctrl-c Description Lists files and folders (use ls -l for a long listing) Change directory ( cd.. will go up a directory) Print name of current directory Make a directory Remove a directory Copy a file (use cp r to copy a directory) Move (or rename) a file or directory Remove a file Show file contents Close connection to server Kill the current process CS 261 Data Structures 9
Basic UNIX Commands For more info on a command, use the manual page: $ man ls Tutorial: http://www.ee.surrey.ac.uk/teaching/unix/
Outline Secure Shell Basic UNIX commands Editing text The GNU Compiler Collection (gcc) Setting up your IDE Basic debugging CS 261 Data Structures 11
UNIX Text Editors Nano Easiest choice Command: nano [filename] ctrl-o to save file ctrl-x to exit Emacs Amazingly powerful, steep learning curve Command: emacs [filename] ctrl-x ctrl-s to save file ctrl-x ctrl-o to exit http://www2.lib.uchicago.edu/keith/tcl-course/emacstutorial.html CS 261 Data Structures
Outline Secure Shell Basic UNIX commands Editing text The GNU Compiler Collection (gcc) Setting up your IDE Basic debugging CS 261 Data Structures 13
GCC GCC is the standard UNIX/Linux/Mac OS X compiler for about a dozen languages (e.g., C, C++, Objective C, Fortran, Java) Compiling with GCC: gcc <list of options> sourcefile.c e.g.: gcc -Wall -std=c99 -o test test.c Compiling multiple files: gcc <list of options> <list of source files> e.g.: gcc Wall -std=c99 -o test test1.c test2.c test3.c CS 261 Data Structures 14
Makefile Example A makefile is like a script for the compiler. We ll provide makefiles for many of your assignments so you ll be able to compile by typing make. Contents of a makefile: default:main Executed when you type make main: main.c gcc -Wall std=c99 main.c o main clean: rm main main.o Executed when you type make clean CS 261 Data Structures 15
Make Tutorial http://mrbook.org/tutorials/make/ CS 261 Data Structures 16
Outline Secure Shell Basic UNIX commands Editing text The GNU Compiler Collection (gcc) Setting up your IDE Basic debugging CS 261 Data Structures 17
C Programming IDEs Mac/Linux/Windows: Eclipse CDT Mac only: Xcode Windows only: Visual Studio Note: Eclipse CDT does not come with a C/C++ compiler and Windows does not have a built-in C/C++ compiler either (Linux and Mac usually come with GCC installed). Therefore, using Eclipse CDT on Windows requires installation of a compiler first, for example MinGW. See http://www.eclipse.org/downloads/moreinfo/c.php for more info. CS 261 Data Structures 18
Always Test on UNIX! You can use any IDE to develop and test your C application before submitting. However, UNIX is the environment in which the program will be graded. Make sure your program will compile and run without errors or warnings using GCC on flip.engr.oregonstate.edu. CS 261 Data Structures 19
GIT Usage www.github.com Any questions on obtaining the assignments? git clone username@host:/path/to/repository Add & commit git add <filename> git add * (not recommended with executables) git commit m Commit Message This only commits to local computer! CS 261 Data Structures 20
GIT Usage -git remote v Chck status of remote git remote add origin <git repository link> Configure remote connection git pull origin master It adds the branch info to gitconfig file Use it only first time while setting the new branch or in case of fetch head error while git push. git pull is more preferred command. git pull Pulls the remote changes into local repository git push origin master This pushes to the network repository CS 261 Data Structures 21
GIT Usage Branching Git allows to create many branches of a working repository Useful for testing new ideas while preserving the HEAD code Create new branch: git checkout b <branch_name> Revert to master: git checkout master Delete the branch git branch d <branch_name> Push branch to remote server git push origin <branch_name> CS 261 Data Structures 22
GIT Usage Update and merge git pull Fetches and merges remote changes Git always trys to auto-merge In cases of failure, you will be notified conflicts Edit files manually to resolve conflicts Delete one version and all the auxiliary characters Then git add and commit again CS 261 Data Structures 23
GIT GUI Invoked from git gui CS 261 Data Structures 24
That s all for today! CS 261 Data Structures 25