Xin Liu Sep 16, 2013. Introduction Xin (Shane) Liu PhD Candidate in Computer Science Research Area: Computer Graphics Tutorial Page: pages.cpsc.ucalgary.ca/~liuxin/CPSC453.

Slides:



Advertisements
Similar presentations
CPSC 441 TUTORIAL – JANUARY 16, 2012 TA: MARYAM ELAHI INTRODUCTION TO C.
Advertisements

Makefiles. makefiles Problem: You are working on one part of a large programming project (e. g., MS Word).  It consists of hundreds of individual.c files.
David Notkin Autumn 2009 CSE303 Lecture 20 static make.
1 CSE 390 Lecture 8 Large Program Management: Make; Ant slides created by Marty Stepp, modified by Josh Goodwin
CS 211 Recitation 1 TA: Ishani Chakraborty. Admin stuff Office hours: 5:00-6:00 pm, Tuesdays at Core.
Unix Continuum of Tools Do something once: use the command line Do something many times: –Use an alias –Use a shell script Do something that is complex.
1 CS 201 Makefile Debzani Deb. 2 Remember this? 3 What is a Makefile? A Makefile is a collection of instructions that is used to compile your program.
CS Lecture 11 Outline Compiling C programs using gcc Archiving modules Using Makefiles Debugging using gdb Assignment 3 discussion Lecture 111CS.
CSE328:Computer Graphics OpenGL Tutorial Dongli Zhang Department of Computer Science, SBU Department of Computer Science, Stony.
1 uClinux course Day 3 of 5 The uclinux toolchain, elf format and ripping a “hello world”
Gator Engineering 1 Chapter 2 C Fundamentals Copyright © 2008 W. W. Norton & Company. All rights reserved.
Introduction of C++ language. C++ Predecessors Early high level languages or programming languages were written to address a particular kind of computing.
CSC 215 : Procedural Programming with C C Compilers.
리눅스 : Lecture 5 UNIX 유틸리티 : text editor, compilation (make), …
Jan. 29, 2008(c) Mike Barnoske Introduction to Runtime Debugging Using the Visual C++ IDE COP 4331: OO Processes for SW Development © Dr. David A. Workman.
Compiling & Debugging Quick tutorial. What is gcc? Gcc is the GNU Project C compiler A command-line program Gcc takes C source files as input Outputs.
Lecture 1: Introduction. Pick Your Version of GLUT OpenGL and the GLUT are available for Windows, Linux and many other Operating Systems and platforms.
Computer Engineering 1 nd Semester Dr. Rabie A. Ramadan 2.
Engineering Computing I Chapter 1 – Part A A Tutorial Introduction.
System Programming - LAB 1 Programming Environments.
ITEC 320 C++ Examples.
C Tutorial - Program Organization CS Introduction to Operating Systems.
CSE 232: C++ Programming in Visual Studio Graphical Development Environments for C++ Eclipse –Widely available open-source debugging environment Available.
CSE 232: C++ debugging in Visual Studio and emacs C++ Debugging (in Visual Studio and emacs) We’ve looked at programs from a text-based mode –Shell commands.
1 CSE 390 Lecture 8 Large Program Management: Make; Ant slides created by Marty Stepp, modified by Jessica Miller and Ruth Anderson
Basic Unix Commands CGS 3460, Lecture 6 Jan 23, 2006 Zhen Yang.
Introduction to Programming
Makefiles. Multiple Source Files (1) u Obviously, large programs are not going to be contained within single files. u C provides several techniques to.
Data Display Debugger (DDD)
C++ (intro) Created by Hwansoo Han Edited by Ikjun Yeom.
CPS120: Introduction to Computer Science Compiling a C++ Program From The Command Line.
Java and C++ Transitioning. A simple example public class HelloWorldApp { public static void main(String[] args) { //Display the string. System.out.println("Hello.
© 2012 Pearson Education, Inc. All rights reserved types of Java programs Application – Stand-alone program (run without a web browser) – Relaxed.
Introduction to Objective-C Spring Goals An introduction to Objective-C As implemented by the Apple LLVM Compiler 4.0 (a.k.a. Clang) Only the basics…
Department of Electronic & Electrical Engineering Introduction to C - The Development cycle. Why C? The development cycle. Using Visual Studio ? A simple.
Makefiles Problem: You are working on one part of a large programming project (e. g., MS Word).  It consists of hundreds of individual.c files all linked.
CS429 Computer Architecture Topics Simple C program Basic structure, functions, separate files Compilation Phases, options Assembler GNU style, byte ordering,
First Compilation Rudra Dutta CSC Spring 2007, Section 001.
C P ROGRAMMING T OOLS. C OMPILING AND R UNNING S INGLE M ODULE P ROGRAM.
Computer Science A 1. Course plan Introduction to programming Basic concepts of typical programming languages. Tools: compiler, editor, integrated editor,
C Programming Lecture 3 : C Introduction 1 Lecture notes : courtesy of Woo Kyun and Chang Byung-Mo.
CSc 352 An Introduction to make Saumya Debray Dept. of Computer Science The University of Arizona, Tucson
Sung-Dong Kim Dept. of Computer Engineering, Hansung University Chapter 3 Programming Tools.
Tutorial 1 Writing Your First C++ Program CSC1110C Introduction to Computer Programming By Paul Pun Acknowledgement: Special thanks to Dr. Michael Fung.
1 CS 192 Lecture 4 Winter 2003 December 8-9, 2003 Dr. Shafay Shamail.
Multiple file project management & Makefile
The make utility (original presentation courtesy of Alark Joshi)
Automating Builds with Makefiles
CSE 303 Lecture 17 Makefiles reading: Programming in C Ch. 15
Makefiles.
Large Program Management: Make; Ant
Computer Engineering 1nd Semester
Editor, Compiler, Linker, Debugger, Makefiles
CSE 351 Section 1: HW 0 + Intro to C
Instructor: Ioannis A. Vetsikas
Computer Science 210 Computer Organization
Large Program Management: Make; Ant
សេចក្តីផ្តើមពី Programming
Large Program Management: Make; Ant
Govt. Polytechnic,Dhangar
CSE 390 Lecture 8 Large Program Management: Make; Ant
Large Program Management: Make; Ant
Large Program Management: Make; Ant
EECE.2160 ECE Application Programming
Large Program Management: Make; Ant
Debugging.
Makefiles, GDB, Valgrind
CSE 390 Lecture 8 Large Program Management: Make; Ant
Administrative things
Large Program Management: Make; Ant
Presentation transcript:

Xin Liu Sep 16, 2013

Introduction Xin (Shane) Liu PhD Candidate in Computer Science Research Area: Computer Graphics Tutorial Page: pages.cpsc.ucalgary.ca/~liuxin/CPSC453

What do we need? Computer Graphics C/C++ OpenGL/GLSL GLUT

Rules Linux/Unix: √ Windows: √ Mac OS: × c/c++: √ Java: × Java = ZERO GNU c/c++:√ Visual c++: √ Objective c:×

Getting started with C ++ C/ C ++ The most widely used programming language Operating systems Applications Fast Good for real-time applications Full control of your computer A better understanding of the hardware Can be “dangerous” Professional Good for your future career

C vs. C++ vs. Java Java is the son of C++ Java is a totally different language though C++ is the son of C C++ is a superset of C You can compile pure C with a C++ compiler Java is a good start for c/c++ programming Similar grammar

C++ vs Java – some differences FunctionC++Java ReferenceYes PointerYesNo Garbage collectionNo (new, delete)Yes Operator overloadingYesNo ClassYes StructYesNo DestructorYesNo

Hello world Edit program Compile Run #include “iostream.h” int main () { cout << “Hello\n”; } g++ hello.c –o hello OR g++ -c hello g++ hello.o hello hello

Compile options -Wall Generate many warnings about questionable looking code g++ -Wall myprog.c –o myprog -O Generate optimized code g++ -O myprog.c –o myprog -g Generate code with symbolic info for debugging g++ -g myprog.c myprog

Compiling multi source files A program composed of several souce files, “file1.c”, “file2.c” g++ -file1.c file2.c –o myprog OR g++ -c file1.c g++ -c file2.c g++ file1.o file2.o –o myprog

Make file The “make program” Compile all source files by a “make” command Track changes of source files Recompile only affected files according to the dependency of source files Requires a makefile to define the dependency

Writing a makefile Four basic types of statements Comments any line beginning with a # Macros defined by: name = data used by: $(name), “$(name)” is then replaced by “data” Explicit rules defines the dependency take the form of Example: Implicit rules similar to explicit rules, except listed without commands. uses the suffixes on the files to determine what command to perform targetfile: sourcefiles commands# there is a TAB before each command main: main.c List.h # to create main, these files must exist gcc –o main main.m List.h # the command to create main

Using IDE Functions of an IDE (an Integrated Development Environment) Edit program Generating a makefile automatically Compile program Debug program Run program Popular IDEs Eclipse on Linux-suggested Visual Studio on Windows-suggested Xcode on Mac OS-no OpenGL 3.3

Example – MyColor.h #include class CMyColor { public: double r; double g; double b; CMyColor (double argR = 0.0, double argG = 0.0, double argB = 0.0); void print(); }; CMyColor operator + (const CMyColor& a, const CMyColor& b); CMyColor operator - (const CMyColor& a, const CMyColor& b); CMyColor operator * (const CMyColor& a, const CMyColor& b); CMyColor operator * (const CMyColor& a, const double& k);

Example – MyColor.cpp #include "stdafx.h" #include "MyColor.h" CMyColor:: CMyColor (double argR, double argG, double argB) { r = argR; g = argG; b = argB; } void CMyColor:: print() { printf("[%f, %f, %f]\n", r, g, b); } CMyColor operator + (const CMyColor& a, const CMyColor& b) { return CMyColor(a.r + b.r, a.g + b.g, a.b + b.b); } CMyColor operator - (const CMyColor& a, const CMyColor& b) { return CMyColor(a.r - b.r, a.g - b.g, a.b - b.b); } CMyColor operator * (const CMyColor& a, const CMyColor& b) { return CMyColor(a.r * b.r, a.g * b.g, a.b * b.b); } CMyColor operator * (const CMyColor& a, const double& k) { return CMyColor(k * a.r, k * a.g, k * a.b); }

Example – Colors.cpp #include "MyColor.h" int main(int argc, char* argv[]) { CMyColor clr; clr.print(); CMyColor *pClr = 0; pClr = new CMyColor(1.0, 1.0, 1.0); pClr->print(); CMyColor clr2 = (clr + (*pClr)) * 2.0; clr2.print(); delete pClr; return 0; }

The End