1 ENERGY 211 / CME 211 Lecture 2 September 24, 2008.

Slides:



Advertisements
Similar presentations
A Guide to Unix Using Linux Fourth Edition
Advertisements

Three types of computer languages
 2003 Prentice Hall, Inc. All rights reserved. 1 Machine Languages, Assembly Languages, and High-level Languages Three types of computer languages 1.Machine.
CS 202 Computer Science II Lab Fall 2009 September 3.
1 Using Editors Editors let you create and edit ASCII files UNIX normally includes two editors: vi and Emacs Vi and Emacs are screen editors: they display.
Guide To UNIX Using Linux Third Edition
G++ and make Dan Wilson CS193 02/01/06. The g++ Compiler What happens when you call g++ to build your program? Phase 1, Compilation:.cpp files are compiled.
Lecture 8  make. Overview: Development process  Creation of source files (.c,.h,.cpp)  Compilation (e.g. *.c  *.o) and linking  Running and testing.
The Unix Environment and Compiling. Getting Set Up Your programs will be compiled and tested on the Departmental server ‘linprog’ The linprog servers.
1 ENG236: ENG236: C++ Programming Environment (2) Rocky K. C. Chang THE HONG KONG POLYTECHNIC UNIVERSITY.
Introduction to C++ - How C++ Evolved Most popular languages currently: COBOL, Fortran, C, C++, Java (script) C was developed in 1970s at AT&T (Richie)
Gator Engineering 1 Chapter 2 C Fundamentals Copyright © 2008 W. W. Norton & Company. All rights reserved.
IPC144 Introduction to Programming Using C Week 1 – Lesson 2
리눅스 : Lecture 5 UNIX 유틸리티 : text editor, compilation (make), …
Computer Engineering 1 nd Semester Dr. Rabie A. Ramadan 2.
Old Chapter 10: Programming Tools A Developer’s Candy Store.
Creating your first C++ program
Programming With C.
TAMU CSCE 313 (the basics). Basic Unix/Linux programming Accessing CS systems  PuTTY (putty.exe) – a Telnet and SSH client  Common hosts: unix.cs.tamu.edu.
© 2012 Pearson Education, Inc. All rights reserved. 1-1 Why Java? Needed program portability – Program written in a language that would run on various.
Chapter Ten g++ and make1 System Programming Software Development: g++ and make.
1 Programming in C Hello World! Soon I will control the world! Soon I will control the world!
Getting started: Basics Outline: I.Connecting to cluster: ssh II.Connecting outside UCF firewall: VPN client III.Introduction to Linux IV.Intoduction to.
CS CS CS IA: Procedural Programming CS IB: Object-Oriented Programming.
N from what language did C++ originate? n what’s input, output device? n what’s main memory, memory location, memory address? n what’s a program, data?
Chapter 0 Getting Started. Objectives Understand the basic structure of a C++ program including: – Comments – Preprocessor instructions – Main function.
C Language: Introduction
Algorithms  Problem: Write pseudocode for a program that keeps asking the user to input integers until the user enters zero, and then determines and outputs.
Basic Unix Commands CGS 3460, Lecture 6 Jan 23, 2006 Zhen Yang.
Unix and Samba By: IC Labs (Raj Kidambi). What is Unix?  Unix stands for UNiplexed Information and Computing System. (It was originally spelled "Unics.")
Makefiles, Geany CS 244 Brent M. Dingle, Ph.D. Game Design and Development Program Department of Mathematics, Statistics, and Computer Science University.
Chapter Three The UNIX Editors.
Week Two Agenda Announcements Link of the week Use of Virtual Machine Review week one lab assignment This week’s expected outcomes Next lab assignments.
CPS120: Introduction to Computer Science Compiling a C++ Program From The Command Line.
© 2012 Pearson Education, Inc. All rights reserved types of Java programs Application – Stand-alone program (run without a web browser) – Relaxed.
Object Oriented Programming COP3330 / CGS5409.  Assignment Submission Overview  Compiling with g++  Using Makefiles  Misc. Review.
1 Getting Started with C++ Part 2 Linux. 2 Getting Started on Linux Now we will look at Linux. See how to copy files between Windows and Linux Compile.
THE C PROGRAMMING ENVIRONMENT. Four parts of C environment  Main menu  Editor status line and edit window  Compiler message window  “Hot Keys” quick.
Emacs, Compilation, and Makefile C151 Multi-User Operating Systems.
AN INTRO TO UNIX/LINUX COMMANDS BY: JIAYANG WANG.
CSE 1320 Basics Dr. Sajib Datta
Chapter 11  Getting ready to program  Hardware Model  Software Model  Programming Languages  Facts about C++  Program Development Process  The Hello-world.
Object Oriented Programming COP3330 / CGS5409.  Compiling with g++  Using Makefiles  Debugging.
C Programming Lecture 3 : C Introduction 1 Lecture notes : courtesy of Woo Kyun and Chang Byung-Mo.
1 Types of Programming Language (1) Three types of programming languages 1.Machine languages Strings of numbers giving machine specific instructions Example:
UNIX Development: g++ and make CS 2204 Class meeting 8 Created by Doug Bowman, 2001 Modified by Mir Farooq Ali, 2002.
Sung-Dong Kim Dept. of Computer Engineering, Hansung University Chapter 3 Programming Tools.
L071 Introduction to C Topics Compilation Using the gcc Compiler The Anatomy of a C Program Reading Sections
Some of the utilities associated with the development of programs. These program development tools allow users to write and construct programs that the.
Object Oriented Programming COP3330 / CGS5409.  Assignment Submission Overview  Compiling with g++  Using Makefiles  Misc. Review.
 CSC 215 : Procedural Programming with C C Compilers.
C Copyright © 2009, Oracle. All rights reserved. Using SQL Developer.
Review Why do we use protection levels? Why do we use constructors?
CSC 215 : Procedural Programming with C
CS1010: Intro Workshop.
Computer Terms Review from what language did C++ originate?
Chapter 1: Introduction to computers and C++ Programming
Beginning C++ Programming
Guide To UNIX Using Linux Third Edition
Computer Engineering 1nd Semester
A Guide to Unix Using Linux Fourth Edition
CISC/CMPE320 - Prof. McLeod
Introduction to C Topics Compilation Using the gcc Compiler
CSCI/CMPE 3334 Systems Programming
Compilers, Make and SubVersion
CS IA: Procedural Programming CS IB: Object-Oriented Programming
Appendix F C Programming Environment on UNIX Systems
Computer Terms Review from what language did C++ originate?
Chapter 2 part #1 C++ Program Structure
SPL – PS1 Introduction to C++.
Presentation transcript:

1 ENERGY 211 / CME 211 Lecture 2 September 24, 2008

2 Evolution In the beginning, we all used assembly That was too tedious, so a very crude compiler for FORTRAN was built FORTRAN was still too painful to work with, so ALGOL 60 was created ALGOL 60 merged with COBOL to form CPL, for both science and business

3 Evolution, cont’d CPL was too large and complex, so it was simplified to obtain BCPL BCPL was stripped down even more for systems programming, leading to B B was stripped down too much for more advanced operating systems, so it was enhanced to create C

4 From C to C++ Bjarne Stroustrup wanted a language that was efficient, like C, AND suitable for development of large applications, like SIMULA He enhanced C with SIMULA-like features to create “C with classes” Rick Mascitti first used the name C++ First commercial release in 1985

5 Design Considerations There is no lower-level language between C++ and machine language (can write assembly in C++, but few do) For backward compatibility, any valid C program is a valid C++ program Unlike other languages, C++ supports multiple programming paradigms, such as procedural, object-oriented, generic, functional, etc.

6 From the Text you Type to the Program you Run As with other languages, you type your source code into source files, using the editor of your choice A C++ compiler translates the source code into object code, after checking for errors A linker combines your object code with other object code from existing libraries to create an executable file

7 Tools Needed for Projects Projects will be submitted electronically and graded on the elaine workstations Must have ssh client to connect Must be able to edit files in UNIX/Linux (with vi or emacs, for example), or transfer them using SecureFX Must be able to use GNU C++ compiler Visit computing.stanford.edu for needed software

8 Essential Software Link

9 Link to Download Page

10 Download SecureCRT

11 Launch SecureCRT

12 Create New Session

13 New Session Wizard

14 New Session Wizard, cont’d

15 New Session Wizard, cont’d

16 Connect to Elaine

17 Use SUNet Password

18 Connected!

19 Getting Started in Linux

20 Launching the vi editor

21 VERY Basic vi Usage Type i to enter insert mode Use ESC key to exit insert mode Commands (when not in insert mode): –h : left, l : right, j : down, k : up –x : delete character at cursor Colon takes you to command prompt. There, use w to save, and q to exit Resource for learning vi: –

22 Typing in your program

23 Saving…

24 …saved!

25 Exiting vi

26 Creating Executables in Linux The c++ command invokes the GNU C++ compiler on given source files, indicated by.cpp extension By default, it will also invoke the linker to create an executable –Use –c option to only create an object file which has.o extension By default, executable is called a.out –Use –o option to specify another name –Can be run from the command prompt

27 Compiling and Executing

28 Dissecting hello.cpp // #include is a preprocessor directive that // specifies a header file to be included in the // program (in this case, iostream) #include // When a program is run, its main function is // invoked. It returns an integer (int) value // indicating its status (not done here, though) int main() { // std::cout denotes the “standard output” // device, which is normally the screen. The // << operator, in this case, is used to // write data to this device. std::cout << "Hello world!" << std::endl; }

29 Delegating (or: Modularity!) #include void say_hello() // void means “does not return a value” { std::cout << "Hello world!" << std::endl; } void say_hello(); // external functions must be declared int main() { say_hello(); // main passes the buck to say_hello } hellomain.cpp: (main program) hello.cpp: (subroutine)

30 Compiling Multiple Files Neither hello.cpp nor hellomain.cpp is a complete program, so we use –c to compile only, and not link bramble06:~/demo211> c++ -c hello.cpp bramble06:~/demo211> c++ -c hellomain.cpp The previous commands created object (.o) files, which are now linked to create the executable program “hello” bramble06:~/demo211> c++ -o hello hello.o hellomain.o The ls command lists the current directory (like dir in Windows). The a.out is from before bramble06:~/demo211> ls a.out hello hello.cpp hello.o hellomain.cpp hellomain.o The “.” is used to denote the current directory, which, by default, is not in the search path used to locate programs bramble06:~/demo211>./hello Hello world! bramble06:~/demo211>

31 Managing Projects with make Managing projects with several source files can be tedious When you modify a source file, you need to recompile that file, and re-link The make command recompiles any out-of-date files automatically Useful for tasks such as cleaning up unnecessary files or changing compiler options

32 Creating Makefiles The make command uses a file called Makefile to determine how to proceed Makefile contains rules of the form target: prerequisites command where command builds target from the prerequisites Can define variables for convenience

33 Sample Makefile # All object files that must be linked into final executable OBJ= hello.o hellomain.o # Rule for building executable from object files # is shorthand for the target of the rule hello: ${OBJ} c++ -o ${OBJ} # Rule for compiling individual sources files into object files # $< is shorthand for the first prerequisite ${OBJ}: %.o: %.cpp c++ -c $< # Rule to clean up all output files clean: rm -f hello ${OBJ}

34 Using make With the Makefile, building executable is easy! bramble06:~/demo211> make c++ -c hello.cpp c++ -c hellomain.cpp c++ -o hello hello.o hellomain.o Reset hello.cpp’s modified time to force recompile bramble06:~/demo211> touch hello.cpp Note that only hello.cpp is recompiled bramble06:~/demo211> make c++ -c hello.cpp c++ -o hello hello.o hellomain.o This removes all output files bramble06:~/demo211> make clean rm -f hello hello.o hellomain.o

35 Alternative Approaches Can edit source files on your computer, and transfer using SecureFX (available on Essential Software page), or Fetch if you’re using a Mac Can do all of your work in Windows using MinGW Developer Studio In this case, should still compile and run final program on elaine before submitting

36 MinGW Developer Studio Abbreviated as MDS Available from MDS is an Integrated Development Environment (IDE), with editing, compiling and debugging performed inside the studio Uses gcc compiler

37 Launching MDS

38 Creating a New Project

39 MDS Project View

40 Adding a New Source File

41 Typing in Your Code

42 Building the Executable

43 The Build Process

44 Executing in MDS

45 Execution of Console App

46 What About Mac Users? Mac OS X is built on top of FreeBSD UNIX, so Linux discussion applies Can use ssh to connect to elaine OS X does not come with GNU compilers Can obtain freely from Apple Developer Connection by downloading xcode package (registration required) Visit

47 Next Time Learning some fundamentals of C++ Program Structure Simple Variables Literals Types Basic Exception Handling