Podcast
Questions and Answers
Which of the following best describes a software development tool chain?
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?
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?
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?
What does it mean that some tools in the C tool chain are 'hiding' inside others?
Why might a C programmer working with *nix-family operating systems benefit from understanding the broader C tool chain?
Why might a C programmer working with *nix-family operating systems benefit from understanding the broader C tool chain?
When a program utilizes dynamically linked libraries, what is the primary role of ld.so
during the program's startup?
When a program utilizes dynamically linked libraries, what is the primary role of ld.so
during the program's startup?
What action does the operating system take when a program uses dlopen
to load a shared object plugin at runtime?
What action does the operating system take when a program uses dlopen
to load a shared object plugin at runtime?
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?
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?
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?
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?
A developer wants to ensure that the loader includes the current directory in its search path for shared libraries. What should the developer do?
A developer wants to ensure that the loader includes the current directory in its search path for shared libraries. What should the developer do?
Which component of the C compiler toolchain is responsible for generating errors related to missing libraries?
Which component of the C compiler toolchain is responsible for generating errors related to missing libraries?
When compiling StructListDemo.c
and linking it with the liblist.so
library located in the current directory, which gcc
command is correctly structured?
When compiling StructListDemo.c
and linking it with the liblist.so
library located in the current directory, which gcc
command is correctly structured?
What does the error message "error while loading shared libraries: liblist.so: cannot open shared object file: No such file or directory" typically indicate?
What does the error message "error while loading shared libraries: liblist.so: cannot open shared object file: No such file or directory" typically indicate?
What is the primary role of the loader in the context of executing a compiled C program that utilizes shared libraries?
What is the primary role of the loader in the context of executing a compiled C program that utilizes shared libraries?
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?
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?
What is the primary role of the C preprocessor in the C toolchain?
What is the primary role of the C preprocessor in the C toolchain?
Which of the following is NOT a typical function of the C preprocessor?
Which of the following is NOT a typical function of the C preprocessor?
Which of the following best describes the relationship between an IDE and the underlying toolchain?
Which of the following best describes the relationship between an IDE and the underlying toolchain?
What is the role of the linker in the C compilation process?
What is the role of the linker in the C compilation process?
Which component of the C toolchain is responsible for converting assembly code into machine code?
Which component of the C toolchain is responsible for converting assembly code into machine code?
What is the primary difference between static and dynamic linking?
What is the primary difference between static and dynamic linking?
What does the -save-temps
flag do when compiling C code with GCC?
What does the -save-temps
flag do when compiling C code with GCC?
Why does the linker need explicit paths to non-standard libraries?
Why does the linker need explicit paths to non-standard libraries?
What option is used to specify an additional directory for the linker to search for libraries?
What option is used to specify an additional directory for the linker to search for libraries?
Which of the following describes the purpose of a Makefile
?
Which of the following describes the purpose of a Makefile
?
Which of the following statements is correct regarding the GNU Compiler Collection (GCC)?
Which of the following statements is correct regarding the GNU Compiler Collection (GCC)?
If you get a /usr/bin/ld: cannot find -lsomeLibrary: No such file or directory
error, what is the most likely cause?
If you get a /usr/bin/ld: cannot find -lsomeLibrary: No such file or directory
error, what is the most likely cause?
Where should you add a statement to avoid retyping it every time you log in?
Where should you add a statement to avoid retyping it every time you log in?
What is the purpose of the provided Makefile
in the context of the list library?
What is the purpose of the provided Makefile
in the context of the list library?
Which of the following commands correctly links a program myCode.c
with the math library?
Which of the following commands correctly links a program myCode.c
with the math library?
How do macros defined with #define
get processed during compilation?
How do macros defined with #define
get processed during compilation?
What is the role of the linker?
What is the role of the linker?
What is the difference between the C preprocessor directive #include <header.h>
and #include "header.h"
?
What is the difference between the C preprocessor directive #include <header.h>
and #include "header.h"
?
When linking the list library, how is it referred to, deviating from its actual filename liblist.so
?
When linking the list library, how is it referred to, deviating from its actual filename liblist.so
?
What type of error is indicated by 'undefined reference' during the compilation of StructListDemo.c
?
What type of error is indicated by 'undefined reference' during the compilation of StructListDemo.c
?
Assume myCode.c
uses a function from libcustom.so
located in the same directory. Which compilation command would ensure successful linking?
Assume myCode.c
uses a function from libcustom.so
located in the same directory. Which compilation command would ensure successful linking?
The compilation of StructListDemo.c
fails with 'undefined reference' errors. What is the most likely cause?
The compilation of StructListDemo.c
fails with 'undefined reference' errors. What is the most likely cause?
Which of the following is NOT a typical action performed by a linker?
Which of the following is NOT a typical action performed by a linker?
Which action is essential to resolve the 'undefined reference' errors when compiling StructListDemo.c
after compiling the liblist.so
library?
Which action is essential to resolve the 'undefined reference' errors when compiling StructListDemo.c
after compiling the liblist.so
library?
Considering the compilation process of StructListDemo.c
and the use of liblist.so
, what is the role of the linker?
Considering the compilation process of StructListDemo.c
and the use of liblist.so
, what is the role of the linker?
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?
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?
Flashcards
Tool Chain
Tool Chain
The sequence of software tools that transforms source code into binary code.
Software Development Tools
Software Development Tools
Languages, libraries, and software used to create a software project.
Compiler
Compiler
Converts human-readable source code into machine-executable binary code.
CIS*2750 Languages
CIS*2750 Languages
Signup and view all the flashcards
*nix-family OS
*nix-family OS
Signup and view all the flashcards
Loader Function
Loader Function
Signup and view all the flashcards
ld.so
ld.so
Signup and view all the flashcards
dlopen
dlopen
Signup and view all the flashcards
ldd Command
ldd Command
Signup and view all the flashcards
LD_LIBRARY_PATH
LD_LIBRARY_PATH
Signup and view all the flashcards
IDE (Integrated Development Environment)
IDE (Integrated Development Environment)
Signup and view all the flashcards
GCC (GNU Compiler Collection)
GCC (GNU Compiler Collection)
Signup and view all the flashcards
Clang Compiler
Clang Compiler
Signup and view all the flashcards
Linker
Linker
Signup and view all the flashcards
Loader
Loader
Signup and view all the flashcards
Make
Make
Signup and view all the flashcards
C Preprocessor (cpp)
C Preprocessor (cpp)
Signup and view all the flashcards
#include
#include
Signup and view all the flashcards
External References
External References
Signup and view all the flashcards
Static Linking
Static Linking
Signup and view all the flashcards
Dynamic Linking
Dynamic Linking
Signup and view all the flashcards
-l option
-l option
Signup and view all the flashcards
-lm
-lm
Signup and view all the flashcards
Default Library Paths
Default Library Paths
Signup and view all the flashcards
-L flag
-L flag
Signup and view all the flashcards
Linker Error: Library Not Found
Linker Error: Library Not Found
Signup and view all the flashcards
.bashrc file
.bashrc file
Signup and view all the flashcards
Library
Library
Signup and view all the flashcards
Compile library
Compile library
Signup and view all the flashcards
Header Files (.h)
Header Files (.h)
Signup and view all the flashcards
Binary Files (.so)
Binary Files (.so)
Signup and view all the flashcards
Compiler Flags
Compiler Flags
Signup and view all the flashcards
Linking Errors
Linking Errors
Signup and view all the flashcards
Linking a Library
Linking a Library
Signup and view all the flashcards
The Linker
The Linker
Signup and view all the flashcards
Linking libraries
Linking libraries
Signup and view all the flashcards
-llist
-llist
Signup and view all the flashcards
Shared Library Load Error
Shared Library Load Error
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>
.
- Searches a file named file as follows:
-
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()
instdio.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 thesomeLibrary
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 functionmain()
.
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.
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.