Top Banner
Week 4: Compilation and Singly Linked List Tae-Hyuk (Ted) Ahn Department of Computer Science Program of Bioinformatics and Computational Biology Saint Louis University CSCI 2100 Data Structures Fall 2019
17

csci2100 week4 1 · CSCI 2100 3 A Brief History and Introduction to GCC The originalGNU C Compiler(GCC) is developed by Richard Stallman, the founder of theGNU Project.Richard Stallman

Jun 18, 2020

Download

Documents

dariahiddleston
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: csci2100 week4 1 · CSCI 2100 3 A Brief History and Introduction to GCC The originalGNU C Compiler(GCC) is developed by Richard Stallman, the founder of theGNU Project.Richard Stallman

Week 4: Compilation and Singly Linked List

Tae-Hyuk (Ted) AhnDepartment of Computer Science

Program of Bioinformatics and Computational BiologySaint Louis University

CSCI 2100 Data Structures Fall 2019

Page 2: csci2100 week4 1 · CSCI 2100 3 A Brief History and Introduction to GCC The originalGNU C Compiler(GCC) is developed by Richard Stallman, the founder of theGNU Project.Richard Stallman

2CSCI 2100

Student OutcomesAfter this lecture, students are expected to understand

● Compile and build with multiple files including header file.

● Develop a singly-linked list

Page 3: csci2100 week4 1 · CSCI 2100 3 A Brief History and Introduction to GCC The originalGNU C Compiler(GCC) is developed by Richard Stallman, the founder of theGNU Project.Richard Stallman

3CSCI 2100

A Brief History and Introduction to GCCThe original GNU C Compiler (GCC) is developed by Richard Stallman, the founder of the GNU Project. Richard Stallman founded the GNU project in 1984 to create a complete Unix-like operating system as free software, to promote freedom and cooperation among computer users and programmers.

● GCC, formerly for "GNU C Compiler", has grown over times to support many languages such as C (gcc), C++ (g++), Objective-C, Objective-C++, Java (gcj), Fortran (gfortran), Ada (gnat), Go (gccgo), OpenMP, Cilk Plus, and OpenAcc. It is now referred to as "GNU Compiler Collection". The mother site for GCC is http://gcc.gnu.org/.

● GCC is a key component of so-called "GNU Toolchain", for developing applications and writing operating systems. The GNU Toolchain includes:§ GNU Compiler Collection (GCC): a compiler suite that supports many languages, such as C/C++ and Objective-C/C++.§ GNU Make: an automation tool for compiling and building applications.§ GNU Binutils: a suite of binary utility tools, including linker and assembler.§ GNU Debugger (GDB).§ GNU Autotools: A build system including Autoconf, Autoheader, Automake and Libtool.§ GNU Bison: a parser generator (similar to lex and yacc).

● GCC is portable and run in many operating platforms. GCC (and GNU Toolchain) is currently available on all Unixes. They are also ported to Windows (by Cygwin, MinGW and MinGW-W64). GCC is also a cross-compiler, for producing executables on different platform.

Page 4: csci2100 week4 1 · CSCI 2100 3 A Brief History and Introduction to GCC The originalGNU C Compiler(GCC) is developed by Richard Stallman, the founder of theGNU Project.Richard Stallman

4CSCI 2100

GCC Versions

The various GCC versions are:

● GCC version 1 (1987): Initial version that support C.

● GCC version 2 (1992): supports C++.

● GCC version 3 (2001): incorporating ECGS (Experimental GNU Compiler System), with improve optimization.

● GCC version 4 (2005):

● GCC version 5 (2015):

● GCC Version 6 (2016):

● GCC Version 7 (2017):

Page 5: csci2100 week4 1 · CSCI 2100 3 A Brief History and Introduction to GCC The originalGNU C Compiler(GCC) is developed by Richard Stallman, the founder of theGNU Project.Richard Stallman

5CSCI 2100

C++ Standard Support

There are various C++ standards:

● C++98

● C++11 (aka C++0x)

● C++14 (aka C++1y)

● C++17 (aka C++1z)

● C++2a (next planned standard in 2020)

Page 6: csci2100 week4 1 · CSCI 2100 3 A Brief History and Introduction to GCC The originalGNU C Compiler(GCC) is developed by Richard Stallman, the founder of theGNU Project.Richard Stallman

6CSCI 2100

C++ versions

● What version of C++ am I using now?

● What version of g++ am I using now?

Page 7: csci2100 week4 1 · CSCI 2100 3 A Brief History and Introduction to GCC The originalGNU C Compiler(GCC) is developed by Richard Stallman, the founder of theGNU Project.Richard Stallman

7CSCI 2100

My g++ version check

https://gcc.gnu.org/projects/cxx-status.htmlhttps://gcc.gnu.org/onlinedocs/gcc/Standards.html

Page 8: csci2100 week4 1 · CSCI 2100 3 A Brief History and Introduction to GCC The originalGNU C Compiler(GCC) is developed by Richard Stallman, the founder of theGNU Project.Richard Stallman

8CSCI 2100

How to explicitly compile using C++11,14,17?$ g++ -std=c++11 source.cpp –o output$ g++ -std=c++14 source.cpp –o output

Page 9: csci2100 week4 1 · CSCI 2100 3 A Brief History and Introduction to GCC The originalGNU C Compiler(GCC) is developed by Richard Stallman, the founder of theGNU Project.Richard Stallman

9CSCI 2100

The compilation of a C++

● Preprocessing: the preprocessor takes a C++ source code file and deals with the #includes, #defines and other preprocessor directives. The output of this step is a "pure" C++ file without pre-processor directives.

● Compilation: the compiler takes the pre-processor's output and produces an object file from it.

● Linking: the linker takes the object files produced by the compiler and produces either a library or an executable file.

Page 10: csci2100 week4 1 · CSCI 2100 3 A Brief History and Introduction to GCC The originalGNU C Compiler(GCC) is developed by Richard Stallman, the founder of theGNU Project.Richard Stallman

10CSCI 2100

Compiling and Linking

$ g++ -o main.exe main.cpp

$ g++ -c main.cpp$ g++ -o main.exe main.o

Page 11: csci2100 week4 1 · CSCI 2100 3 A Brief History and Introduction to GCC The originalGNU C Compiler(GCC) is developed by Richard Stallman, the founder of theGNU Project.Richard Stallman

11CSCI 2100

Separating class code into a header and cpp file

Ask

$ g++ -o main.exe add.cpp main.cpp

Page 12: csci2100 week4 1 · CSCI 2100 3 A Brief History and Introduction to GCC The originalGNU C Compiler(GCC) is developed by Richard Stallman, the founder of theGNU Project.Richard Stallman

12CSCI 2100

GCD project with three files

Page 13: csci2100 week4 1 · CSCI 2100 3 A Brief History and Introduction to GCC The originalGNU C Compiler(GCC) is developed by Richard Stallman, the founder of theGNU Project.Richard Stallman

13CSCI 2100

rectangle.h

Page 14: csci2100 week4 1 · CSCI 2100 3 A Brief History and Introduction to GCC The originalGNU C Compiler(GCC) is developed by Richard Stallman, the founder of theGNU Project.Richard Stallman

14CSCI 2100

rectangle.cpp

Page 15: csci2100 week4 1 · CSCI 2100 3 A Brief History and Introduction to GCC The originalGNU C Compiler(GCC) is developed by Richard Stallman, the founder of theGNU Project.Richard Stallman

15CSCI 2100

rectangle_test.cpp

Page 16: csci2100 week4 1 · CSCI 2100 3 A Brief History and Introduction to GCC The originalGNU C Compiler(GCC) is developed by Richard Stallman, the founder of theGNU Project.Richard Stallman

16CSCI 2100

makefile● Finally, we note that for larger problems, there are other tools to assist developers in managing their

projects. ● For example, many Integrated Development Environments (IDEs) will keep track of which pieces of

source code have been modified, and which need to be re-compiled when building a new executable. ● One of the classic tools for developers in managing the (re)building of a project is a program known

as make. This program relies upon a configuration file for the project, conventionally named makefile.

● The makefile designates what components comprise the project, and upon which pieces of source code each component depends. The make command causes a re-build of the entire project, but relying on the file-system timestamps to determine which pieces of source code have been edited since the previous build.

Page 17: csci2100 week4 1 · CSCI 2100 3 A Brief History and Introduction to GCC The originalGNU C Compiler(GCC) is developed by Richard Stallman, the founder of theGNU Project.Richard Stallman

17CSCI 2100

Object demo and makefile examplehopper:/public/ahnt/courses/csci2100/demos/objectdemo