Skip to content

Instantly share code, notes, and snippets.

@peterhellberg
Last active September 13, 2024 09:50
Show Gist options
  • Save peterhellberg/804af84fefa07cf826d578e4f36e5b61 to your computer and use it in GitHub Desktop.
Save peterhellberg/804af84fefa07cf826d578e4f36e5b61 to your computer and use it in GitHub Desktop.
Trying out the cram-snap template for Typst
#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.
],
)
Display the source blob
Display the rendered blob
Raw
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
viewBox="0 0 38.000089 42.000031"
width="380.00089"
height="420.00031"
version="1.1"
id="svg10"
sodipodi:docname="icons8-c-programming.svg"
inkscape:version="1.0.1 (3bc2e813f5, 2020-09-07)">
<metadata
id="metadata16">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title></dc:title>
</cc:Work>
</rdf:RDF>
</metadata>
<defs
id="defs14" />
<sodipodi:namedview
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1"
objecttolerance="10"
gridtolerance="10"
guidetolerance="10"
inkscape:pageopacity="0"
inkscape:pageshadow="2"
inkscape:window-width="1920"
inkscape:window-height="1056"
id="namedview12"
showgrid="false"
fit-margin-top="0"
fit-margin-left="0"
fit-margin-right="0"
fit-margin-bottom="0"
inkscape:zoom="1.4895833"
inkscape:cx="190"
inkscape:cy="210.00282"
inkscape:window-x="0"
inkscape:window-y="0"
inkscape:window-maximized="1"
inkscape:current-layer="svg10" />
<path
fill="#283593"
fill-rule="evenodd"
d="m 17.903,0.28628166 c 0.679,-0.381 1.515,-0.381 2.193,0 C 23.451,2.1692817 33.547,7.8372817 36.903,9.7202817 37.582,10.100282 38,10.804282 38,11.566282 c 0,3.766 0,15.101 0,18.867 0,0.762 -0.418,1.466 -1.097,1.847 -3.355,1.883 -13.451,7.551 -16.807,9.434 -0.679,0.381 -1.515,0.381 -2.193,0 -3.355,-1.883 -13.451,-7.551 -16.807,-9.434 -0.678,-0.381 -1.096,-1.084 -1.096,-1.846 0,-3.766 0,-15.101 0,-18.867 0,-0.762 0.418,-1.466 1.097,-1.8470003 3.354,-1.883 13.452,-7.551 16.806,-9.43400004 z"
clip-rule="evenodd"
id="path2"
style="fill:#004482;fill-opacity:1" />
<path
fill="#5c6bc0"
fill-rule="evenodd"
d="m 0.304,31.404282 c -0.266,-0.356 -0.304,-0.694 -0.304,-1.149 0,-3.744 0,-15.014 0,-18.759 0,-0.758 0.417,-1.458 1.094,-1.8360003 3.343,-1.872 13.405,-7.507 16.748,-9.38000004 0.677,-0.379 1.594,-0.371 2.271,0.008 3.343,1.87200004 13.371,7.45900004 16.714,9.33100004 0.27,0.152 0.476,0.335 0.66,0.5760003 z"
clip-rule="evenodd"
id="path4"
style="fill:#659ad2;fill-opacity:1" />
<path
fill="#ffffff"
fill-rule="evenodd"
d="m 19,7.0002817 c 7.727,0 14,6.2730003 14,14.0000003 0,7.727 -6.273,14 -14,14 -7.727,0 -14,-6.273 -14,-14 0,-7.727 6.273,-14.0000003 14,-14.0000003 z m 0,7.0000003 c 3.863,0 7,3.136 7,7 0,3.863 -3.137,7 -7,7 -3.863,0 -7,-3.137 -7,-7 0,-3.864 3.136,-7 7,-7 z"
clip-rule="evenodd"
id="path6" />
<path
fill="#3949ab"
fill-rule="evenodd"
d="m 37.485,10.205282 c 0.516,0.483 0.506,1.211 0.506,1.784 0,3.795 -0.032,14.589 0.009,18.384 0.004,0.396 -0.127,0.813 -0.323,1.127 l -19.084,-10.5 z"
clip-rule="evenodd"
id="path8"
style="fill:#00599c;fill-opacity:1" />
</svg>
@peterhellberg
Copy link
Author

C-Compilation-Process-Essentials

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment