Software Development Toolchain
41 Questions
0 Views

Choose a study mode

Play Quiz
Study Flashcards
Spaced Repetition
Chat to Lesson

Podcast

Play an AI-generated podcast conversation about this lesson

Questions and Answers

Which of the following best describes a software development tool chain?

  • A graphical interface used for designing and prototyping software applications quickly.
  • A sequence of software tools that transforms source code into executable binary code. (correct)
  • A collection of pre-written code snippets that can be reused across different projects.
  • A suite of tools designed for managing software versions and collaboration among developers.

Why is understanding the tool chain important for software developers?

  • It simplifies the process of writing code, as developers do not need to worry about compilation or linking.
  • It helps in selecting the most expensive tools to ensure high-quality software.
  • It enables developers to optimize the build process, debug effectively, and understand how code transforms into an executable. (correct)
  • It is essential for adhering to specific coding standards imposed by the operating system.

In the context of the CIS*2750 course, which programming languages are primarily used for different parts of the assignments?

  • Python for the native portion and C for the UI/database portion to leverage rapid development.
  • Java for the native portion and JavaScript for the UI/database portion.
  • C++ for both the native and UI/database portions to ensure performance.
  • C for the native portion and Python/SQL for the UI/database portion. (correct)

What does it mean that some tools in the C tool chain are 'hiding' inside others?

<p>Some tools are integrated or invoked by other tools, making their operation less visible. (C)</p> Signup and view all the answers

Why might a C programmer working with *nix-family operating systems benefit from understanding the broader C tool chain?

<p>Because it allows for better optimization, debugging, and control over the compilation process specific to those environments. (D)</p> Signup and view all the answers

When a program utilizes dynamically linked libraries, what is the primary role of ld.so during the program's startup?

<p>It loads libraries on demand, resolving references to library functions only when they are first called during the program's execution. (C)</p> Signup and view all the answers

What action does the operating system take when a program uses dlopen to load a shared object plugin at runtime?

<p>The OS pauses the program's execution, loads and links the shared object into the already-loaded code, and then resumes execution. (B)</p> Signup and view all the answers

A developer has compiled a program my_program on a Linux system that depends on shared libraries. Which command should the developer use to list these dependencies?

<p><code>ldd my_program</code> (B)</p> Signup and view all the answers

Why might a shared library located in the current directory fail to load, even if it is a dependency of a program being executed in that directory?

<p>The current directory is not included in the default search paths used by the loader. (D)</p> Signup and view all the answers

A developer wants to ensure that the loader includes the current directory in its search path for shared libraries. What should the developer do?

<p>Set the <code>LD_LIBRARY_PATH</code> environment variable to include the current directory. (B)</p> Signup and view all the answers

Which component of the C compiler toolchain is responsible for generating errors related to missing libraries?

<p>The linker (A)</p> Signup and view all the answers

When compiling StructListDemo.c and linking it with the liblist.so library located in the current directory, which gcc command is correctly structured?

<p><code>gcc StructListDemo.c -L. -llist</code> (D)</p> Signup and view all the answers

What does the error message "error while loading shared libraries: liblist.so: cannot open shared object file: No such file or directory" typically indicate?

<p>The operating system cannot locate the shared library at runtime. (C)</p> Signup and view all the answers

What is the primary role of the loader in the context of executing a compiled C program that utilizes shared libraries?

<p>To locate and load shared libraries required by the executable. (B)</p> Signup and view all the answers

If you encounter the error "cannot open shared object file" when running your compiled program, and the library libmylib.so is located in the program's current directory, what is the most appropriate way to resolve this?

<p>Set the <code>LD_LIBRARY_PATH</code> environment variable to include the current directory. (A)</p> Signup and view all the answers

What is the primary role of the C preprocessor in the C toolchain?

<p>To interpret and process preprocessor directives before compilation. (C)</p> Signup and view all the answers

Which of the following is NOT a typical function of the C preprocessor?

<p>Optimizing machine code. (B)</p> Signup and view all the answers

Which of the following best describes the relationship between an IDE and the underlying toolchain?

<p>The IDE abstracts and manages the toolchain, but the same tools are used. (B)</p> Signup and view all the answers

What is the role of the linker in the C compilation process?

<p>To combine object files and libraries into an executable program. (D)</p> Signup and view all the answers

Which component of the C toolchain is responsible for converting assembly code into machine code?

<p>The assembler (C)</p> Signup and view all the answers

What is the primary difference between static and dynamic linking?

<p>Static linking incorporates the code of required functions and variables directly into the executable file, while dynamic linking only notes which library to use at runtime. (C)</p> Signup and view all the answers

What does the -save-temps flag do when compiling C code with GCC?

<p>It saves the intermediate files generated during compilation. (A)</p> Signup and view all the answers

Why does the linker need explicit paths to non-standard libraries?

<p>The linker only searches a predefined set of system directories for libraries by default. (C)</p> Signup and view all the answers

What option is used to specify an additional directory for the linker to search for libraries?

<p><code>-L</code> (A)</p> Signup and view all the answers

Which of the following describes the purpose of a Makefile?

<p>It automates the build process by defining dependencies and compilation steps. (C)</p> Signup and view all the answers

Which of the following statements is correct regarding the GNU Compiler Collection (GCC)?

<p>GCC is a free, open-source compiler available on many platforms. (A)</p> Signup and view all the answers

If you get a /usr/bin/ld: cannot find -lsomeLibrary: No such file or directory error, what is the most likely cause?

<p>The linker is not looking in the directory where <code>someLibrary</code> is located. (B)</p> Signup and view all the answers

Where should you add a statement to avoid retyping it every time you log in?

<p>The <code>.bashrc</code> file in your home directory. (B)</p> Signup and view all the answers

What is the purpose of the provided Makefile in the context of the list library?

<p>To compile the library to create a binary file called <code>liblist.so</code>. (D)</p> Signup and view all the answers

Which of the following commands correctly links a program myCode.c with the math library?

<p><code>gcc myCode.c -lm</code> (D)</p> Signup and view all the answers

How do macros defined with #define get processed during compilation?

<p>They are expanded by the preprocessor through find-and-replace. (C)</p> Signup and view all the answers

What is the role of the linker?

<p>To find and incorporate external function and variable definitions into the executable file. (A)</p> Signup and view all the answers

What is the difference between the C preprocessor directive #include <header.h> and #include "header.h"?

<p>The angle brackets <code>&lt;&gt;</code> tell the preprocessor to search in system directories, while the quotes <code>&quot;&quot;</code> tell it to search in the current directory first. (B)</p> Signup and view all the answers

When linking the list library, how is it referred to, deviating from its actual filename liblist.so?

<p>It is referred to as <code>list</code>. (A)</p> Signup and view all the answers

What type of error is indicated by 'undefined reference' during the compilation of StructListDemo.c?

<p>The linker cannot find the implementation of the <code>initializeList</code> and <code>insertBack</code> functions. (A)</p> Signup and view all the answers

Assume myCode.c uses a function from libcustom.so located in the same directory. Which compilation command would ensure successful linking?

<p><code>gcc myCode.c -L. -lcustom</code> (A)</p> Signup and view all the answers

The compilation of StructListDemo.c fails with 'undefined reference' errors. What is the most likely cause?

<p>The compiled <code>liblist.so</code> library is not being linked during the compilation of <code>StructListDemo.c</code>. (A)</p> Signup and view all the answers

Which of the following is NOT a typical action performed by a linker?

<p>Loading shared libraries into memory at runtime. (A)</p> Signup and view all the answers

Which action is essential to resolve the 'undefined reference' errors when compiling StructListDemo.c after compiling the liblist.so library?

<p>Specify the path to the <code>liblist.so</code> library when compiling <code>StructListDemo.c</code>. (B)</p> Signup and view all the answers

Considering the compilation process of StructListDemo.c and the use of liblist.so, what is the role of the linker?

<p>To combine the compiled object code of <code>StructListDemo.c</code> with the compiled code from <code>liblist.so</code>, resolving external references. (C)</p> Signup and view all the answers

What would be the correct gcc command to compile StructListDemo.c and link it with the list library, assuming liblist.so is in the current directory?

<p><code>gcc StructListDemo.c -L. -llist</code> (A)</p> Signup and view all the answers

Flashcards

Tool Chain

The sequence of software tools that transforms source code into binary code.

Software Development Tools

Languages, libraries, and software used to create a software project.

Compiler

Converts human-readable source code into machine-executable binary code.

CIS*2750 Languages

C for native code, Python/SQL for UI/database components.

Signup and view all the flashcards

*nix-family OS

Unix-like operating systems.

Signup and view all the flashcards

Loader Function

Copies program segments into memory, including text and data.

Signup and view all the flashcards

ld.so

Loads dynamically linked libraries when the program starts.

Signup and view all the flashcards

dlopen

Loads shared object 'plugins' on demand at runtime.

Signup and view all the flashcards

ldd Command

Command used to see shared object dependencies on Linux.

Signup and view all the flashcards

LD_LIBRARY_PATH

Environment variable to specify where to find shared libraries.

Signup and view all the flashcards

IDE (Integrated Development Environment)

An application that provides a comprehensive environment for software development, including code editing, compiling, and debugging.

Signup and view all the flashcards

GCC (GNU Compiler Collection)

A popular family of compilers, including a C compiler, widely used in software development; known for being free and open source.

Signup and view all the flashcards

Clang Compiler

Alternative to GCC. Free, open-source, available on multiple platforms and installed with Xcode on macOS.

Signup and view all the flashcards

Linker

A utility that combines object files, libraries, and other components to create an executable program.

Signup and view all the flashcards

Loader

Loads the executable program into memory and starts its execution.

Signup and view all the flashcards

Make

A build automation tool that manages the compilation and linking process, especially for large projects.

Signup and view all the flashcards

C Preprocessor (cpp)

A program that processes source code before compilation, handling directives like #include and #define.

Signup and view all the flashcards

#include

A C preprocessor directive that inserts the content of another file into the current source file.

Signup and view all the flashcards

External References

Tables in object files that list external functions or variables used in the code but defined elsewhere.

Signup and view all the flashcards

Static Linking

A linking method where the function code and global variables are copied directly into the program file.

Signup and view all the flashcards

Dynamic Linking

A linking method where the program only saves a reference to the external function inside a library that is resolved at runtime.

Signup and view all the flashcards

-l option

Option used with the compiler (gcc) to link a specific library during compilation.

Signup and view all the flashcards

-lm

The standard shortcut used when linking the C math library using GCC.

Signup and view all the flashcards

Default Library Paths

Directories where the linker automatically searches for library files by default.

Signup and view all the flashcards

-L flag

Option used with the compiler to specify additional directories where the linker should search for library files.

Signup and view all the flashcards

Linker Error: Library Not Found

An error during linking when the linker can't find a specified library file in the default or provided paths.

Signup and view all the flashcards

.bashrc file

A file in your home directory that is executed when you log in.

Signup and view all the flashcards

Library

A collection of pre-written code (functions, variables, etc.) that can be used by other programs.

Signup and view all the flashcards

Compile library

Compiling the library creates a binary file, making functions available for other code.

Signup and view all the flashcards

Header Files (.h)

Header files contain declarations of functions, types, and variables that can be used in other source files.

Signup and view all the flashcards

Binary Files (.so)

Binary files contain compiled code that can be executed by a computer.

Signup and view all the flashcards

Compiler Flags

Tells the compiler where to find header files and library files needed to compile the program.

Signup and view all the flashcards

Linking Errors

The linker is part of the C compiler toolchain. Generated when there is a missing reference.

Signup and view all the flashcards

Linking a Library

Specify the location of library headers and the library binary file for compilation.

Signup and view all the flashcards

The Linker

Reports missing library errors during the compilation process.

Signup and view all the flashcards

Linking libraries

Tell the linker to link with the library and specify its location.

Signup and view all the flashcards

-llist

Instructs the linker to link with a specific library.

Signup and view all the flashcards

Shared Library Load Error

The program reports it can't find a shared library; tell the loader where to look for it.

Signup and view all the flashcards

Study Notes

  • Volunteer notetakers are needed to share class notes with students registered with Student Accessibility Services.
  • Volunteers make a one-semester commitment and notes are shared only with approved students.
  • More info: uoguel.ph/notetaker

What is a Tool Chain?

  • Developing software projects is inherently linked to the development tools, languages, libraries, and the additional software.
  • The term "tool chain" describes the sequence of software tools converting source code (text files) into binary code.
  • A tool chain includes more than just the compiler and involves a sequence of tools.

Course Overview

  • This course uses C for the "native" portion (A1-A2) and Python/SQL for the UI/database portion (A3).
  • The first half of the course will cover C.
  • It will also cover tools used by C programmers working with *nix-family OS.
  • The lecture will then show how they "chain" in sequence with each other.
  • The course raises tools knowledge from the level of ritualized to one of knowledge.

The Common Tools

  • C Preprocessor
  • C Compiler
  • Linker
  • Loader
  • Make

IDE

  • Integrated Development Environments (IDEs) manage tools.
  • An IDE is an Interactive Development Environment.
  • Windows Visual Studio is available on other platforms.
  • macOS has Xcode for its IDE.
  • Multi-platform IDEs: Eclipse, IntelliJ, Codelite, CodeBlocks.
  • Different languages have different tool chains, as it's possible for an IDE to accommodate more than one.

C Compilers

  • Several C compilers exist.
  • Popular FOSS compilers:
  • GNU Compiler Collection (GCC) is widely usage.
    • It's free, open-source, and often installed default with Linux.
  • Clang is a more recent alternative to GCC.
    • It's free, open-source, available on many platforms, installed on macOS with Xcode
  • GCC and Clang implement C standards and provide custom extensions.
  • The course uses the C compiler from GCC.

How the C toolchain works

  • Files within the project include .h and .c extensions

  • Those go through several stages.

  • C Preprocessor (cpp*):

    • Uses command line options CPPFLAGS and LDFLAGS
    • Output an .i file
  • C Compiler (gcc*):

    • Uses command line options CFLAGS
    • Outputs a .s file
  • Assembler (gas):

    • Uses command line options SFLAGS
    • Outputs a .o or .obj file
  • Linker (ld*):

    • Links .o/.obj files with other .a/.lib and .so/.dll resources
    • Outputs an executable: prog.out, a.out, .exe
  • Loader:

    • loads the new executable with ld.so and possibly dlopen
    • Loads into the process memory
  • Make can manage the process

  • Build time data flows up the chain to runtime

Intermediate Files Note

  • Intermediate files (.i, .s, .o) are not always generated by default.
  • The use of the .o files are sometimes created.
  • .i and .s files are not usually needed.
  • To view them, use the -save-temps flag when compiling.

C Preprocessor Explained

  • Purpose is to interpret the # directives in .h and .c files before the compiler processes the source code.
  • #include: merges header files.
  • #define: creates macros, with or without arguments. Expanded by processor.
  • #ifdef, if, else, endif: used for conditional compilation.
  • #pragma: passed as a compiler directive only ignored if the compiler doesn't recognize it.
  • "cpp" is often used as abbreviation for the C preprocessor, which is confusing because "cpp" is also a common acronym and an extension for C++ source files.
  • "cpp" means "C preprocessor"

Prevent includes

  • Best practice pattern is the ".h" pattern
  • In file headername.h:
    • #ifndef HEADERNAME_H
    • #define HEADERNAME_H
    • ...body of .h file...
    • #endif
  • The symbol HEADERNAME_H gets created on the first #include “headername.h”
  • File contents are skipped, if included again

Headers and Paths

  • The #include directive has different syntax for different headers.

  • #include <file>: for system header files.

    • Searches a standard list directory for the file.
  • #include "file": header files of programs.

    • Searches a file named file as follows:
      • first in the directory containing the current file.
      • then in the "quote" directories.
      • then the same directories used for <file>.
  • Paths to the file must no go in the #include statement.

  • Not: #include "../includeDir/Parser.h"

  • If files move, the path breaks

  • Include the file itself: #include "Parser.h".

  • The compiler toolchain will deal with the paths.

  • You can use -I option to pass header file directories to the compiler.

    • gcc -I../includeDir myFile.c
    • gcc -I../includeDir -I/home/username/stuff/otherIncludeDir myFile.c
  • Paths used in a command can be relative or absolute.

C Compiler tool explained

  • Purpose: Compile C language source code (.i file) into assembly language (.s).
  • Issues warnings/errors and diagnoses abuses of language.
  • Intermediate .i and .s files deleted after assembly unless requested with the -save-temps option.
  • See the sample .c, .i, .s, etc. files in the GCC_intermediate_files.zip example.
  • Compile with gcc -save-temps test.c.

Assembler

  • Purpose: Assemble assembly code (.s) from compiler into object code (.o).
  • This step is very transparent.
  • There are rarely used options to control settings.
  • Assembly statements can utilize vector instructions for the CPU's vector processing unit.

Linker

  • It stitches together objects (.o) into a single binary program file, like an executable or library.
  • Includes all the .o object files that make up the user program.
  • Considers all the referenced system libraries.

Linker Libraries

  • Static libraries (.a / .lib): inserted in the executable file.
  • Dynamic libraries (.so / .dll): linked in at run time.

How Linking Works

  • Object files have tables of external references (e.g., call printf).
  • Reads all libraries until matching external definition found (e.g., code for printf() in stdio.h).
  • Libraries are linked differently depending on the format.
  • Static Linking:
    • pulls definitions (function code, global variables) into the program, fixes refs to point to their locations.
  • Dynamic Linking:
    • makes a note to note which library file to get the def at runtime.

Linking and Paths

  • The linker automatically links standard C libraries, excluding the math library.
  • Other required libraries need to be explicitly passed to the linker with the -l option.
  • To link the C math library, add the -lm option to the compiler.
  • Discussed in a later lecture is the convention on library naming.

Linking Path Info

  • The linker needs to know the disk location of the libraries, and by default looks in certain system directories.

  • For example /usr/lib, /usr/local/lib.

  • It's important to note that the linker does not look in the current directory.

  • If both myCode.c and the someLibrary are in the same directory, the compiler will throw an error /usr/bin/ld: cannot find -IsomeLibrary: No such file or directory

  • To give the linker additional locations use the -L flag.

  • For example gcc myCode.c -L/path/to/a/library -lsomeLibrary

  • In this case use: gcc myCode.c -L. -lsomeLibrary

Preprocessor and Linker paths

  • -I: provides paths for the preprocessor.
  • Locations of header files for #include.
  • -L: provides paths to the linker for library locations.
  • -l: provides names of libraries for the linker to link with.

Why gcc Is Involved

  • GCC acts as a front end for {cpp, gcc, ld}.
  • To get these tools, you keep executing "gcc".
  • GCC is calling them for you: gcc is not cpp or ld.
  • gcc knows where all standard libraries are installed, and beefs up *FLAGS for you.

Loader

  • Examined steps concerned with creating binary files.
  • Next is looking at what happens with that binary when executed.
  • Program tells OS to execute a program file.
  • OS creates a fresh process.
  • Segments of the program file are copied to different areas of the virtual memory for the process.
  • Program instructions ("text" segment)
  • Static data ("data" segment)
  • OS creates a new stack and an empty heap.
  • Then, OS transfers control to the first instruction of the program.

Loader and Dynamic Libraries

  • ld.so will load dynamic linked libraries when a program starts.
  • References (calls) will be fixed on demand.
  • Because most of libraries will not referenced.
  • Some programs use dlopen to load a Shared Object plugin at runtime.
  • OS pauses execution while loader grabs the object, links into code, continue.

Loader Paths

  • To see dependencies on Linux, use ldd {file}.
  • For example, ldd a.out.
  • The loader has to know where to find shared runtime libraries.
  • To see what directories the loader knows, check /etc/ld.so.conf.d.

Loader Directory Paths

  • By default, the current directory is not included, and it's not checked.
  • Fix this with the environment variable, LD_LIBRARY_PATH:
    • export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:.
  • The statement should be added to the end of .bashrc to avoid retyping.
  • It facilitates loading the List API library and linking the A1 parser library.

Compiling list library

  • The sample code for list library consists of three files:
    • LinkedListAPI.c: Library function implementations.
    • LinkedListAPI.h: Library headers (function prototypes, etc.).
    • StructListDemo.c: Demo executable with function main().

To Successfully Run an Example

  • It's neccessary to Compile the library

  • Then compile demo, which requires

    • the location of library headers
    • the location of the linked library file
    • the library path
    • the library binary file name
  • Libraries compiled using Makefile makes a binary file called liblist.so

  • When linking a listed library, one refers to it as a list.

StructListDemo example

  • When compiling the executable demo file with gcc StructListDemo.c, you encounter errors.
/usr/bin/ld: /tmp/ccUliKAO.o: in function `main':
StructListDemo.c:(.text+0x1f4): undefined reference to
`initializeList'
/usr/bin/ld: StructListDemo.c:(.text+0x2d4): undefined reference to
`insertBack'
...
  • The C compiler toolchain component that generates this error is the linker.
  • Solution: tell the library to link and where it is.

To Correctly Create Example

  • gcc StructListDemo.c -L. -llist
  • -L. tells the linker to look in current directory, additional to global path.
  • -llist tells the linker to link with the listed library.
  • This library is called liblist.so.
  • After creating example. if run, the code throws an open shared object error.
./StructListDemo: error while loading shared libraries: liblist.so:
cannot open shared object file: No such file or directory
  • The loader is the cause of this error.
  • This is fixed by telling it to look in the same directory.

Studying That Suits You

Use AI to generate personalized quizzes and flashcards to suit your learning preferences.

Quiz Team

Related Documents

Description

This quiz explores software development toolchains, their importance for developers, and specific tools used in CIS*2750. It covers dynamic linking with ld.so, runtime loading with dlopen, and listing shared library dependencies.

More Like This

Mastering the Go Toolchain
6 questions

Mastering the Go Toolchain

IngenuousSpessartine avatar
IngenuousSpessartine
Aula 2 - Microcontrolador
59 questions

Aula 2 - Microcontrolador

SelfDeterminationOmaha avatar
SelfDeterminationOmaha
C Programming Toolchain Concepts
38 questions

C Programming Toolchain Concepts

ComfortableBowenite2676 avatar
ComfortableBowenite2676
Use Quizgecko on...
Browser
Browser