What is the difference between static and dynamic linking?

The lesson mentions 'linking' the SDL libraries to our project. What exactly is linking, and what's the difference between static and dynamic linking?

Linking is the process of combining the object files generated during compilation into a single executable file. The linker resolves symbolic references between object files and library files.

There are two ways a library can be linked to an application - statically or dynamically:

Static linking means the library code is copied into the executable at compile time. The advantage is that the executable is self-contained and can run on its own. The disadvantages are that the executable is larger, and if the library is updated, the application needs to be recompiled.

Dynamic linking means the library code is not copied into the executable. Instead, the executable contains a reference to the library, which is resolved at runtime. The advantages are smaller executable size and the ability to update the library without recompiling the application. The main disadvantage is that the required .dll or .so files must be present on the user's system.

In general, dynamic linking is more flexible and is used by most modern libraries and applications. Static linking is mainly used in embedded systems or where absolute minimum dependencies are required.

Setting up SDL2 in Windows (Visual Studio)

A step-by-step tutorial on configuring SDL2, SDL_image and SDL_ttf in a Visual Studio C++ project on Windows

Questions & Answers

Answers are generated by AI models and may not have been reviewed. Be mindful when running any code on your device.

What is the difference between SDL and SDL2?
I see references to both SDL and SDL2. What's the difference between them and which one should I use for a new project?
Why do I need to copy the DLL files to my executable directory?
The lesson says to copy the SDL .dll files to the same directory as my .exe file. Why is this necessary? Can't I just keep them in the SDL library directories?
What do the SDL_Init, IMG_Init and TTF_Init functions do?
The example code calls SDL_Init, IMG_Init and TTF_Init. What are these functions actually doing?
How can I troubleshoot unresolved external symbol linker errors?
I tried to set up SDL following the lesson, but I'm getting 'unresolved external symbol' errors when I try to compile. How can I troubleshoot this?
What are some common SDL compilation errors and how can I fix them?
Apart from linker errors, what other kinds of compilation errors might I encounter when starting with SDL, and how can I troubleshoot them?
Or Ask your Own Question
Get an immediate answer to your specific question using our AI assistant