Skip to content

I have spend shit while setting up#24

Open
Butcher3Years wants to merge 1 commit intoUsing--Librariesfrom
Dynamic--Libraries
Open

I have spend shit while setting up#24
Butcher3Years wants to merge 1 commit intoUsing--Librariesfrom
Dynamic--Libraries

Conversation

@Butcher3Years
Copy link
Copy Markdown
Owner

Dynamic Libraries in C++ – DLL Hell & Linking Pain (Cherno Style) 🪓💀

Branch: dynamic-libraries
From The Cherno's C++ series — the episodes where he screams about linker errors, missing DLLs at runtime, and why dynamic linking is both a blessing and a curse.

What the Fuck is a Dynamic Library?

A dynamic library (.dll on Windows, .so on Linux, .dylib on macOS) is compiled code that your program loads at runtime instead of baking into your .exe.

  • Static lib (.lib/.a) → compiled into your exe → bigger file, no runtime dependency
  • Dynamic lib (.dll/.so) → separate file → smaller exe, can update lib without recompiling

Cherno:

"Dynamic libs let you update OpenGL driver or game engine without touching your exe.
But if the DLL is missing or wrong version — your program just dies at launch. Welcome to DLL hell."

Why Use Dynamic Libraries?

  • Smaller exe (code not duplicated)
  • Share libs across programs (system DLLs like kernel32.dll)
  • Update lib without recompiling (graphics drivers, plugins)
  • Load plugins at runtime (mod support in games)

How Dynamic Linking Works (Step-by-Step)

  1. Compile your code with headers
    #include <GLFW/glfw3.h>

  2. Tell linker where to find import lib

    • .lib file (Windows) or .so (Linux) contains symbols table
    • Linker resolves symbols → adds dependency info to exe
  3. At runtime — OS loads DLL

    • Looks in exe folder, PATH env, system folders
    • If DLL missing → "The application was unable to start correctly (0xc000007b)" or similar

Using a Dynamic Lib (GLFW Example – Cherno Style)

  1. Download GLFW pre-built binaries (or build yourself)

  2. Copy files:

    • Headers → include/GLFW/
    • glfw3.dll → next to your exe (or in PATH)
    • glfw3.lib (Windows import lib) → your lib folder
  3. Compile command (g++/MinGW)

g++ main.cpp -Iinclude -Llib -lglfw3 -lopengl32 -lgdi32 -o game.exe

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant