What happens to global and static variables in a shared library when it is dynamically linked?

This is a pretty famous difference between Windows and Unix-like systems. No matter what: Each process has its own address space, meaning that there is never any memory being shared between processes (unless you use some inter-process communication library or extensions). The One Definition Rule (ODR) still applies, meaning that you can only have one … Read more

What is the -fPIE option for position-independent executables in gcc and ld?

PIE is to support address space layout randomization (ASLR) in executable files. Before the PIE mode was created, the program’s executable could not be placed at a random address in memory, only position independent code (PIC) dynamic libraries could be relocated to a random offset. It works very much like what PIC does for dynamic … Read more

Embedding DLLs in a compiled executable

I highly recommend to use Costura.Fody – by far the best and easiest way to embed resources in your assembly. It’s available as NuGet package. Install-Package Costura.Fody After adding it to the project, it will automatically embed all references that are copied to the output directory into your main assembly. You might want to clean … Read more

How does the compilation/linking process work?

The compilation of a C++ program involves three steps: Preprocessing: the preprocessor takes a C++ source code file and deals with the #includes, #defines and other preprocessor directives. The output of this step is a “pure” C++ file without pre-processor directives. Compilation: the compiler takes the pre-processor’s output and produces an object file from it. … Read more