Intro to GCC Chaps 2,4,11

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

Give an example of the -c option

$ gcc -Wall -c main.c This produces an object file 'main.o' containing the machine code for the main function. It contains a reference to the external function hello, but the corresponding memory address is left undefined in the object file at this stage (it will be filled in later by linking).

Which command do you use to compile the 'hello.c' file with gcc?

$ gcc -Wall hello.c -o hello

what extensions do libraries usually have?

'.a'

Which file extensions are given to C plus programs and C++ programs, respectively, during teleprocessing?

'.i' for C programs and '.ii' for C++ programs

what is the sequence of commands executed by a single invocation of GCC?

1. preprocessing (to expand macros) 2. compilation (from source code to assembly language) 3. assembly (from assembly language to machine code) 4. linking (to create the final executable)

What is a Library?

A library is a collection of precompiled object files which can be linked into programs

How does the make program work?

A makefile specifies a set of compilation rules in terms of targets (such as executables) and their dependencies (such as object files and source files) in the following format: target: dependencies command For each target, make checks the modification time of the corresponding dependency files to determine whether the target needs to be rebuilt using the corresponding command. Note that the command lines in a makefile must be indented with a single TAB character, not spaces.

Which type of message indicates a potential problem but does not prevent the file from compiling?

A warning Message

Which type of error message prevents a file from compiling?

An error message

what does the linker do?

An object file contains machine code where any references to the memory addresses of functions (or variables) in other files are left undefined. This allows source files to be compiled without direct reference to each other. The linker fills in these missing addresses when it produces the executables

where should other files that are used by the program by specified

At the top of the program in quotes

Give and example of how a make file will be executed in the command line

CC=gcc CFLAGS=-Wall main: main.o hello_fn.o clean: rm -f main main.o hello_fn.o The file can be read like this: using the C compiler gcc, with compilation option -Wall, build the target executable main from the object files 'main.o' and 'hello_fn.o' (these, in turn, will be built via implicit rules from 'main.c' and 'hello_fn.c'). The target clean has no dependencies and simply removes all the compiled files.(4) The option -f (force) on the rm command suppresses any error messages if the files do not exist.

How does the Make program recompile a file?

For each target, make checks the modification time of the corresponding dependency files to determine whether the target needs to be rebuilt using the corresponding command. Note that the command lines in a makefile must be indented with a single TAB character, not spaces.

What are the defaut rules of GNU

GNU Make contains many default rules, referred to as implicit rules, to simplify the construction of makefiles. For example, these specify that '.o' files can be obtained from '.c' files by compilation, and that an executable can be made by linking together '.o' files. Implicit rules are defined in terms of make variables, such as CC (the C compiler) and CFLAGS (the compilation options for C programs), which can be set using VARIABLE=VALUE lines in the makefile. For C++ the equivalent variables are CXX and CXXFLAGS, while the make variable CPPFLAGS sets the preprocessor options. The implicit and user-defined rules are automatically chained together as necessary by GNU Make.

which unix program can be used to only recompile the modified files of a program?

Make

which option is used to compile a file?

The command-line option -c is used to compile a source file to an object file

what will happen if a file is compiled with the name of a file that already exists in the current directory?

The existing file will be over written

What is a linker?

The linker combines all the object files to create a single executable.

What happens during the linking stage?

The object files are linked to create an executable.

what does the '-wall' option do?

The option -Wall turns on all the most commonly-used compiler warnings---it is recommended that you always use this option! There are many other warning options which will be discussed in later chapters, but -Wall is the most important. GCC will not produce any warnings unless they are enabled. Compiler warnings are an essential aid in detecting problems when programming in C and C++.

What needs to be done if changes are made to a function in a program that is stored in a single file

The program needs to be recompiled to produce a new executable.

What happens during the Assembly stage?

The purpose of the assembler is to convert assembly language into machine code and generate an object file. When there are calls to external functions in the assembly source file, the assembler leaves the addresses of the external functions undefined, to be filled in later by the linker.

What will happen if this command is ran?: $ gcc -Wall hello.c -o hello

This compiles the source code in 'hello.c' to machine code and stores it in an executable file 'hello'. The output file for the machine code is specified using the -o option. This option is usually given as the last argument on the command line. If it is omitted, the output is written to a default file called 'a.out'.

How does gcc perform the linking of files

To perform the linking step gcc uses the linker ld, which is a separate program.

How do you run a program?

To run a program type the path name of the executable like this: $ ./hello This loads the executable file into memory and causes the CPU to begin executing the instructions contained within it. The path ./ refers to the current directory, so ./hello loads and runs the executable file 'hello' located in the current directory.

What happens during the Compilation stage?

What happens during the Reprocessing stage?

how are libraries created?

libraries are created from object files and are created by using a tool called GNU archiver

what format is used to for messages produced by gcc?

line-number:message

Do all of the files of a program that is stored in separate locations need to be recompiled if a change is made to the functions of 1 file?

no. only the file that was modified needs to be changed

What happens during the Reprocessing stage?

the preprocessor to expand macros and included header files.

Where are libraries usually stored?

the standard system libraries are usually found in the directories '/usr/lib' and '/lib'.(5) For example, the C math library is typically stored in the file '/usr/lib/libm.a' on Unix-like systems. The corresponding prototype declarations for the functions in this library are given in the header file '/usr/include/math.h'. The C standard library itself is stored in '/usr/lib/libc.a' and contains functions specified in the ANSI/ISO C standard, such as 'printf'---this library is linked by default for every C program.

How are object files linked?

they are simply listed on the command line: $ gcc main.o hello_fn.o -o hello This is one of the few occasions where there is no need to use the -Wall warning option, since the individual source files have already been successfully compiled to object code. Once the source files have been compiled, linking is an unambiguous process which either succeeds or fails (it fails only if there are references which cannot be resolved).


Kaugnay na mga set ng pag-aaral

Chapter 5: Fetal Development, Chapter 5: Fetal Development

View Set

Cumulative Trauma Disorders (CTD) of UE

View Set

Anatomy Lecture Exam 2 Fun fact / ICS

View Set