csci2100 week4 1 · csci 2100 3 a brief history and introduction to gcc the originalgnu c...

Post on 18-Jun-2020

7 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

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

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

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.

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):

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)

6CSCI 2100

C++ versions

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

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

7CSCI 2100

My g++ version check

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

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

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.

10CSCI 2100

Compiling and Linking

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

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

11CSCI 2100

Separating class code into a header and cpp file

Ask

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

12CSCI 2100

GCD project with three files

13CSCI 2100

rectangle.h

14CSCI 2100

rectangle.cpp

15CSCI 2100

rectangle_test.cpp

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.

17CSCI 2100

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

top related