Last active
September 13, 2024 09:50
-
-
Save peterhellberg/804af84fefa07cf826d578e4f36e5b61 to your computer and use it in GitHub Desktop.
Trying out the cram-snap template for Typst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import "@preview/cram-snap:0.1.0": cram-snap | |
#set page( | |
paper: "a3", | |
flipped: true, | |
margin: 1cm, | |
) | |
#set text(font: "Inter", weight: "regular", size: 8pt) | |
#show raw: it => text( | |
font: "Office Code Pro D", | |
weight: "medium", | |
size: 8pt, | |
it) | |
#show: cram-snap.with( | |
title: [Compilation Process Essentials], | |
icon: image("C_Programming_Language.svg"), | |
column-number: 2, | |
) | |
#table( | |
table.header(table.cell(colspan: 2)[ | |
1. Common Environment Variables | |
]), | |
table.cell(colspan: 2)[Environment variables are used to control the behavior of compilers, linkers, and build tools.], | |
[`CC`], [Specifies the C compiler to be used (e.g., gcc, clang).], | |
[`CXX`], [Specifies the C++ compiler to be used (e.g., g++, clang++).], | |
[`CFLAGS`], [Specifies the flags to be passed to the C compiler. Common flags include optimization flags (-O2, -O3), debugging flags (-g), and warning flags (-Wall, -Werror).], | |
[`CPPFLAGS`], [Preprocessor flags for both C and C++ compilers. Common flags include -I for including directories and -D for defining macros.], | |
[`LDFLAGS`], [Flags for the linker. Common flags include -L to specify library search paths and -l to link with specific libraries.], | |
[`LD_LIBRARY_PATH`], [Specifies additional paths to search for shared libraries at runtime.], | |
[`PKG_CONFIG_PATH`], [Used by pkg-config to find .pc files for libraries that are not installed in standard locations.], | |
[`MAKEFLAGS`], [Specifies flags to be passed to make. For example, -j4 to use 4 parallel jobs.], | |
) | |
#table( | |
table.header(table.cell(colspan: 2)[ | |
2. Common Compiler Flags | |
]), | |
table.cell(colspan: 2)[ | |
These flags control the behavior of the C compiler (`gcc`, `clang`, etc.). | |
], | |
table.cell(align: top)[*Optimization Flags*], [ | |
`-O0`: No optimization (*default*). | |
`-O1`, `-O2`, `-O3`: Various levels of optimization. `-O3` is the most aggressive. | |
`-Os`: Optimize for size. | |
`-Ofast`: Like `-O3`, but enables some non-standard-compliant optimizations. | |
], | |
table.cell(align: top)[*Debugging Flags*], [ | |
`-g`: Generate debug information to be used by a debugger (e.g., `gdb`). | |
], | |
table.cell(align: top)[*Warning Flags*], [ | |
`-Wall`: Enable most common warnings. | |
`-Wextra`: Enable additional warnings. | |
`-Werror`: Treat all warnings as errors. | |
`-pedantic`: Enforce strict ISO C compliance. | |
], | |
table.cell(align: top)[*Preprocessor Flags*], [ | |
`-I<dir>`: Add a directory to the list of directories to be searched for header files. | |
`-D<macro>`: Define a macro. | |
], | |
table.cell(align: top)[*Output Control Flags*], [ | |
`-o <file>`: Specify the name of the output file. | |
], | |
table.cell(align: top)[*Position-Independent Code (PIC) Flags*], [ | |
`-fPIC`: Generate position-independent code (_useful for shared libraries_). | |
], | |
) | |
#colbreak() | |
#table( | |
table.header(table.cell(colspan: 2)[ | |
3. Common Linker Flags | |
]), | |
table.cell(colspan: 2)[ | |
These flags control the behavior of the linker (`ld`). | |
], | |
table.cell(align: top)[*Library Search Paths*], [ | |
`-L<dir>`: Add a directory to the list of directories to be searched for libraries. | |
], | |
table.cell(align: top)[*Linking Libraries*], [ | |
`-l<name>`: Link with library `lib<name>.so` or `lib<name>.a`. | |
], | |
table.cell(align: top)[*Dynamic vs Static Linking*], [ | |
`-shared`: Create a shared library. | |
`-static`: Link statically with libraries. | |
], | |
table.cell(align: top)[*Debugging and Symbols*], [ | |
`-g`: Include debug symbols. | |
], | |
table.cell(align: top)[*Relocation and Optimization*], [ | |
`-pie`: Create a position-independent executable. | |
`-Wl,--strip-all`: Strip all symbols (_to reduce binary size_). | |
], | |
) | |
#table( | |
table.header(table.cell(colspan: 2)[ | |
4. Build System Specific Variables and Flags | |
]), | |
table.cell(colspan: 2)[ | |
Build systems like `Make`, `CMake`, and `Autotools` use specific variables and flags. | |
], | |
table.cell(align: top)[*Makefile Specifics*],[ | |
`make -j`: Run multiple jobs in parallel for faster builds. | |
`VPATH`: Specifies additional directories to search for source files. | |
`MAKEFLAGS`: Pass flags to the make process itself. | |
], | |
table.cell(align: top)[*CMake Specifics*],[ | |
`CMAKE_C_COMPILER`: Sets the C compiler. | |
`CMAKE_C_FLAGS`: Sets additional flags for the C compiler. | |
`CMAKE_INSTALL_PREFIX`: Specifies the installation directory. | |
`BUILD_SHARED_LIBS`: Controls whether shared libraries are built. | |
], | |
table.cell(align: top)[*Autotools Specifics*],[ | |
`./configure` *options*: Options like `--prefix=<dir>`, `--enable-debug`, `--disable-static`, | |
etc., control how the project is configured. | |
`config.status`: A script that contains the result of the configuration process. | |
`aclocal`, `autoconf`, `automake`: Tools used to generate the configure script and Makefile.in. | |
], | |
) | |
#table( | |
table.header(table.cell(colspan: 2)[ | |
5. Other Useful Tools and Utilities | |
]), | |
table.cell(align: top)[`pkg-config`],[ | |
A helper tool used to configure compiler and linker flags for libraries. | |
], | |
table.cell(align: top)[`ldconfig`],[ | |
Updates the dynamic linker cache for shared libraries. | |
], | |
table.cell(align: top)[`strip`],[ | |
Removes symbols from binary files to reduce their size. | |
], | |
table.cell(align: top)[`ar`],[ | |
A utility to create, modify, and extract from archives (used for static libraries). | |
], | |
table.cell(align: top)[`nm`],[ | |
Lists symbols from object files. | |
], | |
table.cell(align: top)[`objdump`],[ | |
Displays detailed information about object files. | |
], | |
) | |
#table( | |
table.header(table.cell(colspan: 2)[ | |
6. Special Macros and Preprocessor Directives | |
]), | |
table.cell(colspan: 2)[ | |
Macros and preprocessor directives are often used in `C` | |
projects to control compilation based on the environment. | |
], | |
table.cell(align: top)[*Conditional Compilation*],[ | |
`#ifdef, #ifndef, #if, #endif`: Conditionally compile code based on defined macros. | |
], | |
table.cell(align: top)[*Assertions and Debugging*],[ | |
`assert()`: Used for debugging, checks a condition at runtime. | |
], | |
table.cell(align: top)[*Platform Specific Macros*],[ | |
`__linux__`, `_WIN32`, `__APPLE__`: Platform-specific macros for conditional compilation. | |
], | |
) |
Author
peterhellberg
commented
Sep 13, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment