1 C/C++ Compiling. 2 Outline Surfing www.mcsr.olemiss.edu websitewww.mcsr.olemiss.edu Logging into the system via ssh Brief History of C/C++ languages.

Slides:



Advertisements
Similar presentations
Introduction to Fortran and Fortran Compiling. Outline  Surfing websitewww.mcsr.olemiss.edu  Logging into the system via ssh 
Advertisements

CSCI 1411 FUNDAMENTALS OF COMPUTING LAB Lab Introduction 1 Shane Transue MSCS.
Three types of computer languages
Computer Science 117 Intro to C++ 08/26/13. Today Discuss Syllabus Brief History of C++ How to Execute a C++ program. Reading assignment.
The Internet. Telnet Telnet means using your computer as a terminal. All commands you type are sent to the host computer you are connected to and executed.
Basic linux shell commands and Makefiles. Log on to engsoft.rutgers.edu Open SSH Secure Shell – Quick Connect Hostname: engsoft.rutgers.edu Username/password:
CS1020: Intro Workshop. Topics CS1020Intro Workshop Login to UNIX operating system 2. …………………………………… 3. …………………………………… 4. …………………………………… 5. ……………………………………
Course Introduction and Getting Started with C 1 USF - COP C for Engineers Summer 2008.
CMSC 104, Version 9/011 Introduction to C Topics Compilation Using the gcc Compiler The Anatomy of a C Program 104 C Programming Standards and Indentation.
C/C++ Compiling.
Introduction to C. A Brief History Created by Dennis Ritchie at AT&T Labs in 1972 Originally created to design and support the Unix operating system.
Introduction To C++ Programming 1.0 Basic C++ Program Structure 2.0 Program Control 3.0 Array And Structures 4.0 Function 5.0 Pointer 6.0 Secure Programming.
Creating a Console Application with Visual Studio
Prof. R. Willingale Department of Physics and Astronomy 2nd Year C+R 2 nd Year C and R Workshop Part of module PA2930 – 2.5 credits Venue: Computer terminal.
1 C/C++ UM/MCSR Last modified: September 3, 2008.
Copyright 2003 Scott/Jones Publishing Brief Version of Starting Out with C++, 4th Edition Chapter 1 Introduction to Computers and Programming.
The Unix Environment and Compiling. Getting Set Up Your programs will be compiled and tested on the Departmental server ‘linprog’ The linprog servers.
Agenda What is Computer Programming? The Programming Process
Introduction to C Programming. A Brief History u Created by Dennis Ritchie at AT&T Labs in 1972 u Originally created to design and support the Unix operating.
Overview of Linux CS3530 Spring 2014 Dr. José M. Garrido Department of Computer Science.
IPC144 Introduction to Programming Using C Week 1 – Lesson 2
1 C/C++ UM/MCSR. 2 Logging into the system using ssh Logging into the system from Windows: –Start the secure shell client: Start->Programs->SSH.
1 SEEM3460 Tutorial Unix Introduction. 2 Introduction Unix-like system is everywhere Linux Android for smartphones Google Chrome OS for Chromebook Web.
Creating your first C++ program
Programming With C.
O.S.C.A.R. Cluster Installation. O.S.C.A.R O.S.C.A.R. Open Source Cluster Application Resource Latest Version: 2.2 ( March, 2003 )
Introduction to C Programming CE Lecture 7 Compiler options and makefiles.
ENEE150 – 0202 ANDREW GOFFIN Introduction to ENEE150.
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.
Introduction to Fortran Welcome to IT’s seminar on Fortran Sam Gordji, Weir 107.
Basic Unix Commands CGS 3460, Lecture 6 Jan 23, 2006 Zhen Yang.
Creating Programs on UNIX This term you can create programs on UNIX or you can create programs using a C++ compiler on your PC. This set of slides steps.
Oct 2001ANSI C Under Unix (v1.0)1 UNIX C Programming under Unix written and presented by M.T.Stanhope.
CPS120: Introduction to Computer Science Compiling a C++ Program From The Command Line.
Introduction to UNIX CS 2204 Class meeting 1 *Notes by Doug Bowman and other members of the CS faculty at Virginia Tech. Copyright
1 Day 2 Logging in, Passwords, Man, talk, write. 2 Logging in Unix is a multi user system –Many people can be using it at the same time. –Connections.
Introduction to SAS/willow (Unix) Sam Gordji Weir 107.
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.
1 Running MPI on “Gridfarm” Bryan Carpenter February, 2005.
1 Getting Started with C++ Part 1 Windows. 2 Objective You will be able to create, compile, and run a very simple C++ program on Windows, using Microsoft.
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.
 Prepared by: Eng. Maryam Adel Abdel-Hady
 Prepared by: Eng. Maryam Adel Abdel-Hady
L071 Introduction to C Topics Compilation Using the gcc Compiler The Anatomy of a C Program Reading Sections
Object Oriented Programming COP3330 / CGS5409.  Assignment Submission Overview  Compiling with g++  Using Makefiles  Misc. Review.
Assignprelim.1 Assignment Preliminaries © 2012 B. Wilkinson/Clayton Ferner. Modification date: Jan 16a, 2014.
Review Why do we use protection levels? Why do we use constructors?
KYC - Know your compiler Introduction to GCC
Introduction to C Topics Compilation Using the gcc Compiler
Overview of Linux Fall 2016 Dr. Donghyun Kim
How to Program.
ENEE150 Discussion 01 Section 0101 Adam Wang.
Class Projects and Environment
UMBC CMSC 104 – Section 01, Fall 2016
CS1010: Intro Workshop.
How to Start Programming in Linux Environment
Andy Wang Object Oriented Programming in C++ COP 3330
Computer Programming Techniques Semester 1, 1998
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.
Introduction to Programming the WWW I
Creating Programs on UNIX
Introduction to C Topics Compilation Using the gcc Compiler
Andy Wang Object Oriented Programming in C++ COP 3330
Class Projects and Environment
Video Notes.
Introduction to C Topics Compilation Using the gcc Compiler
Working in The IITJ HPC System
Presentation transcript:

1 C/C++ Compiling

2 Outline Surfing websitewww.mcsr.olemiss.edu Logging into the system via ssh Brief History of C/C++ languages Basic Structure and Syntax of C/C++ Programs A quick glance on PICO editor A detailed look on compilers and compiling commands How to run a compiled file Application of C/C++ Compiling

3 Logging into the system using ssh Logging into the system from Windows: –Start the secure shell client: Start->Programs->SSH Secure Shell->Secure Shell Client –Connect to willow: From the secure shell window, click Quick Connect. Then, from the Connect to Remote Host pop-up window, enter: Hostname: HostName User Name: UserName Click Connect. Logging into the system from Unix: –Start the Terminal: Finder  Utilities  Terminal –Type the following command: ssh Enter your password If you are a windows user and you want to download ssh; Go to IT and click on the SSH Secure Shell 3.1 link. Secure Shell 3.1 If you are a Unix user, ssh will come with the operating system

4 A Brief History of C language In the early 1970s, Dennis Ritchie of Bell Laboratories was engaged in a project to develop new operating system. C programming language was then developed. In the early 1980's, also at Bell Laboratories, another C++ language was created. This new language was developed by Bjarne Stroustrup and was called C++ which was designed with OOP (Object Oriented Programming) features added to C without significantly changing the C component.

5 Simple C Program /* Take a number multiply it by 10 and display it */ #include main() { int number, result; printf("Type in a number \n"); scanf("%d", &number); result = number *10; printf("The number multiplied by 10 equals %d\n", result); } Sample Program Output Type in a number 23 The number you typed was 23

6 Simple C++ Program /* Take a number multiply it by 10 and display it */ #include using namespace std; int main() { int number; cout<<"Type in a number \n"; cin>>number; result = number *10; cout<<"The number multiplied by 10 equals “<<number; } Sample Program Output Type in a number 23 The number you typed was 23

7 The PICO Editor General Command –Write editor contents to a file[Ctrl] o –Save the file and exit pico[Ctrl] x –Spell Check[Ctrl] t –Justify the text[Ctrl] j Moving around in your file –Move one character to the right[Ctrl] f or right arrow key –Move one character to the left[Ctrl] b or left arrow key –Move up one line[Ctrl] p or up arrow key –Move down one line[Ctrl] n or down arrow key

8 A detailed look into Compilers and Compiling commands C/C++ Compilers at UM/MCSR: –Intel C++ Compiler on redwood –MIPS C, MIPSpro C, and MIPSpro C++ version 7.4 compilers on Origin 2800 sweetgum –Portland Group, GNU, and MPICH Compilers on Beowulf Cluster mimosa –GNU C Compiler and SUN STUDIO 8 C/C++ Compilers on willow

9 Intel C++ Compiler on redwood Intel C/C++ Compilers(7.1, 8.0, 9.0 and 9.1) –Before using the C/C++ Compiler on redwood, you must first load the appropriate Intel compiler module. –Then, to compile: icc example.c if using the 8.0, 9.0, or 9.1 compiler ecc example.c if using the 7.1 compiler. With Intel compilers, the invocation syntax is the same regardless of whether your source file is C or C++.

10 Loading the appropriate Intel Compiler Module Several versions/builds of Intel compilers are available on redwood. To compile, you must first pick which compiler version module you want to load, then load it. Before you can use the module command, you must source the correct setup file for your shell. –. /usr/share/modules/init/sh (if using ssh) (There should be a space between. and /opt) Then you use the module command: –module list (to see if any other versions of compiler modules are loaded) –module purge (to unload any other versions of compiler modules) –module list (to verify that other versions were successfully unloaded) –module avail (to see what versions of compiler modules are available to load) For example, to load the latest 9.1 version of the C Compilers: –module load c91 –module list These are the names of the modules and the compiler versions they correspond to: –intel-compilers for c 7.1 –intel-compilers for c 8.0 –intel-compilers for c 8.0 –intel-compilers for c 9.0 –intel-compilers for c 9.1

11 Exercise 1: Intel Compiler on Redwood 1.If you have an account on redwood, login to it. 2.Copy the two example source files from /usr/local/examples/c to your working directory: A.cp /usr/local/examples/c/hello.c./hello.c B.cp /usr/local/examples/c/addtwo.cpp./addtwo.cpp 3.Source the appropriate modules environment script for your shell: C.. /usr/share/modules/init/bash 4.Use “module avail” to see which modules are available 5.Load one of the 9.X modules A.module load c91 B.module list 6.Compile/execute the hello.c and addtwo.cpp A.icc hello.c B../a.out C.icc addtwo.cpp D../a.out 7.Clear all loaded modules A.module list B.module clear C.module list

12 Sweetgum and Mimosa Sweetgum: MIPSPro 7.4 Compilers, version 7.4 –To compile with cc/CC on sweetgum, enter: CC example.c –To find out more about compilers, enter: man cc OR man CC Mimosa: PGI CDK 6.1 Compilers –To compile with the C/C++ compilers, enter: /usr/local/apps/pgi-6.1/linux86/6.1/bin/pgCC example.c

13 Willow & Common Compiler Flags Sun Studio C/C++ Compilers, Version 5.5: –To compile with C/C++, enter: cc example.c (C) CC example.c (C++) –Compilers located in /ptmp/studio8/SUNWspro/bin GNU C/C++ Compilers, Version – To compile with C/C++, enter: gcc example.c (C) g++ example.c (C++) –Compilers located in /usr/local/bin Use which to see which compiler version is being found. –which cc –which CC If there are no compilation errors this creates an executable file called a.out. To execute the C/C++ program, enter:./a.out.

14 Exercise 2: Compile C/C++ on willow 1.Log in to willow using the account: student 2.Change to your numbered working directory: –cd 1 3.Compile/execute hello.c using GNU C compiler –gcc hello.c –./a.out 4.Compile/execute addtwo.cpp using Sun’s C++ –CC addtwo.cpp –./a.out 5.Try to compile hello.c using Sun’s C compiler –cc hello.c

15 Example C/C++ Flags cc -c Compile or assemble the source files, but do not link. -S Stop after the stage of compilation proper -E Stop after the preprocessing stage -o newFilename Name executable something besides a.out -V Show the compiler version (SUN) -vShow the compiler version (GNU)

16 Exercise 3: Compiler Options 1.Compile/execute hello.c using GNU C compiler, and name the executable file helloc.exe –gcc hello.c –o helloc.exe –./helloc.exe 2.Determine what version of the GNU compilers are installed –gcc -v –g++ -v 3.Determine version of installed Sun’s compiler –CC –V –/ptmp/studio8/SUNWspro/bin/cc -V

17 GNU C Compiler and SUN STUDIO 8 C/C++ Compilers on willow gcc file1.c command is used to compile and link a C program on willow g++ file1.c command is used to compile and link a C++ program on willow

18 Frequently Asked ?’s on C/C++ Willow 1.How can I compile one or more C/C++ source files into object files without yet linking into an executable program? 2.How can I ensure the compiler will find a C/C++ header file referenced by my program? 3.How can I ensure the compiler will find a pre- compiled module referenced by my program but residing in a system- or user-defined archive library? 4.How can I add my own module to a library archive for others on the system to re-use? Answers here (or in Advanced C/C++ Compiling Unix Camp)

19 How to run compiled files The compiling commands create an executable file known as a.out unless specified otherwise. To execute your program, type./a.out and press Enter.

20 C/C++ source files suffixes.cpp,.cc,.c suffixes are used for C++ programs that are to be preprocessed, compiled and assembled.c for C programs that are to be processed, compiled and assembled.h or preprocessor (header) files

21 File Structure Implementation files (.cpp,.cc,.c) –Methods are implemented Interface files (.h) –Methods and classes are defined –Also called header files Implementation files depend on Interface files. –Interface holds prototypes and definitions –Implementation holds actual code

22 Compilation Details object.h object.cpp main.cpp object.s main.s object.o main.o Output Source codeAssemblyMachine Code