csci2100 week4 1 · csci 2100 3 a brief history and introduction to gcc the originalgnu c...
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](https://reader035.vdocument.in/reader035/viewer/2022062603/5f08b4167e708231d423500e/html5/thumbnails/1.jpg)
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](https://reader035.vdocument.in/reader035/viewer/2022062603/5f08b4167e708231d423500e/html5/thumbnails/2.jpg)
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](https://reader035.vdocument.in/reader035/viewer/2022062603/5f08b4167e708231d423500e/html5/thumbnails/3.jpg)
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](https://reader035.vdocument.in/reader035/viewer/2022062603/5f08b4167e708231d423500e/html5/thumbnails/4.jpg)
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](https://reader035.vdocument.in/reader035/viewer/2022062603/5f08b4167e708231d423500e/html5/thumbnails/5.jpg)
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](https://reader035.vdocument.in/reader035/viewer/2022062603/5f08b4167e708231d423500e/html5/thumbnails/6.jpg)
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](https://reader035.vdocument.in/reader035/viewer/2022062603/5f08b4167e708231d423500e/html5/thumbnails/7.jpg)
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](https://reader035.vdocument.in/reader035/viewer/2022062603/5f08b4167e708231d423500e/html5/thumbnails/8.jpg)
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](https://reader035.vdocument.in/reader035/viewer/2022062603/5f08b4167e708231d423500e/html5/thumbnails/9.jpg)
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](https://reader035.vdocument.in/reader035/viewer/2022062603/5f08b4167e708231d423500e/html5/thumbnails/10.jpg)
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](https://reader035.vdocument.in/reader035/viewer/2022062603/5f08b4167e708231d423500e/html5/thumbnails/11.jpg)
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](https://reader035.vdocument.in/reader035/viewer/2022062603/5f08b4167e708231d423500e/html5/thumbnails/12.jpg)
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](https://reader035.vdocument.in/reader035/viewer/2022062603/5f08b4167e708231d423500e/html5/thumbnails/13.jpg)
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](https://reader035.vdocument.in/reader035/viewer/2022062603/5f08b4167e708231d423500e/html5/thumbnails/14.jpg)
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](https://reader035.vdocument.in/reader035/viewer/2022062603/5f08b4167e708231d423500e/html5/thumbnails/15.jpg)
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](https://reader035.vdocument.in/reader035/viewer/2022062603/5f08b4167e708231d423500e/html5/thumbnails/16.jpg)
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](https://reader035.vdocument.in/reader035/viewer/2022062603/5f08b4167e708231d423500e/html5/thumbnails/17.jpg)
17CSCI 2100
Object demo and makefile examplehopper:/public/ahnt/courses/csci2100/demos/objectdemo