Precept I : Lab Environment, Unix, Bash, Emacs 2012.09.05.
Lab Environment (Linux) Lab machines are administered by TA IP address range (12 machines) 143.248.141.52 ~ 143.248.141.63 Use SSH protocol to communicate with the lab machine PuTTY (Windows) Terminal (Mac OS) ID Your student number Password
Cygwin Provide Linux-like environment in Windows Install Cygwin http://cygwin.com/install.html Install Cygwin Download & run setup.exe Choose any URL to download files
VMware Player Run another OS (Linux, Windows, etc.) on top of main OS https://my.vmware.com/web/vmware/free#desktop_end_user_computing/vmware_player/5_0 Install VMware Download VMware Player for Windows 32-bit and 64-bit Run downloaded file
VMware Player Download Linux (Ubuntu) image file http://www.ubuntu.com/download/desktop Install Linux on VMware Click on “Create a New Virtual Machine” Click on “Browse…” button Add image file downloaded from website Insert information : username, password, etc. Press “Play virtual machine” button
Accessing from Outside KAIST Require virtual private network (VPN) program At first run, use Internet Explorer! kvpn.kaist.ac.kr Log in Press Start
Change Password on All Machines! Connect to the machine with default ID & PASSWORD Type “passwd” In response to “(current) UNIX password:”, type current password In response to “New password:”, type new password. In response to “Retype new password:”, type new password again. Reminder Each machine does not share files It is your responsibility to back up your files Keep the code locally Use the lab machines only for testing and debugging
Unix and Bash
Bash Commands For details, read the handout Most useful commands Description man <function name> open manual page cd <directory name> change directory ls [-al] list files in the directory mkdir <directory name> make directory rmdir <directory name> remove directory less/cat/more <file name> print file content cp <source> <target> copy source file to target mv <source> <target> rename source file to target
Emacs Popular editor Already installed in lab machines Integrated with GCC compiler driver & GDB debugger Already installed in lab machines emacs test.c
Emacs Hotkey Hotkey Description Ctrl-k cut line Ctrl/alt-w cut/copy region Ctrl-y paste copied/cut region Ctrl-x Ctrl-s save file Ctrl-s/r <string> search/recursive string Ctrl-x Ctrl-f <file> open file Ctrl-x 2/3 Split window vertically/horizontally Ctrl-x o move to different window Ctrl-x 1/0 close other/this window Ctrl-x u undo Ctrl-g abort command Ctrl-x Ctrl-c close emacs
gcc209 –E hello.c > hello.i Building C Programs hello.c Source code C language Contains preprocessor directives hello.i Contains declaration of printf() Missing definition of printf() #include <stdio.h> int main(void) { printf("hello, world\n"); return 0; } Preprocess gcc209 –E hello.c > hello.i C Preprocessor … int printf(char *format, …) int main(void) { printf("hello, world\n"); return 0; }
Building C Programs hello.s Source code Assembly language Missing definition of printf() Compile gcc209 –S hello.i C Compiler .section .rodata cGreeting: .asciz “hello, world\n” .section .text .global main .type main, @function main: puchl %ebp movl %esp, %ebp pushl %cGreeting call printf addl $4, $esp movl $0, %eax movl %ebp, %esp popl %ebp ret
Building C Programs hello.o hello Object code Machine language Missing definition of printf() hello Assemble gcc209 –c hello.s Assembler .100101000110100… 11110010000010100… Link gcc209 hello.o –lc -o hello Linker 001010000101000000111110… gcc209 is an abbreviation for gcc –Wall –ansi –pedantic –m32 –march=i386 Shortcut: gcc209 hello.c –o hello