title: Static-linking of SDL2 libraries
body: <p>I am using Windows 7, Code::Blocks and MinGW. I have little to no experience when it comes to compiling/building anything, especially when Code::Blocks doesn't use makefiles.</p>
  
  <p>I downloaded SDL2-devel-2.0.0-mingw.tar.gz (SDL Development Libraries) from <a href="http://www.libsdl.org/tmp/download-2.0.php" rel="noreferrer">http://www.libsdl.org/tmp/download-2.0.php</a>, and I'd like to create a standalone executable using SDL2 libraries, but so far I've always had to bundle the SDL2.dll file with the executable to make it work.</p>
  
  <p>I've heard that I can not static-link dynamic libraries, so my only option seems to be doing something with the source files using the file SDL2-2.0.0.tar.gz (Source Code) from the link I mentioned above. However, I do not know what I should do with those.</p>
  
  <p>What I managed to try with the source files is importing the Visual Studio project to Code::Blocks and building it, but it tells me "sdl-config No such file or directory" (I do not know what triggered that). I'm also not sure if building merely gives me an executable, with which I do not know what I can do to link it to my own executable.</p>
  
  <p>A fool proof idiot's step by step guide would be the best bet to solve this case.</p>
  
  <p>EDIT:</p>
  
  <p>I managed to compile the SDL libraries with the guide Jonas provided, and got a libSDL2.a file.</p>
  
  <p>At first I only added the path of libSDL2.a to "Link libraries:" -section of Code::Blocks, but I got a bunch of errors such as "SDL_Init() not declared in this scope".</p>
  
  <p>In addition to the libSDL2.a path, I also added the path of SDL2-2.0.0\include to the Compiler's search directory as well as the path of SDL2-2.0.0\build.libs to the Linker's search directory. I also wrote this to my test file: #include "SDL.h". My test file now looks like this:</p>
  
  <pre><code>#include "SDL.h"
  
  int main( int argc, char* args[] ) {
      //Start SDL
      SDL_Init( SDL_INIT_EVERYTHING );
      //Quit SDL
      SDL_Quit();
      return 0;
  }
  </code></pre>
  
  <p>It appears it did fix the declaration problem, but now Code::Blocks opened a SDL_mmjoystick.c file and gave me even more errors: "undefined reference to 'waveInClose@4'", "undefined reference to 'waveOutClose@4'", "undefined reference to 'joyGetNumDevs@0'" and tons of other ones.</p>
  
  <p>Here's a screenshot of what's happening, note the different color of #include texts, I'm not sure why that happens: <a href="http://gyazo.com/00656a9c1e57a2bd0db1414fa7d68ced.png" rel="noreferrer">http://gyazo.com/00656a9c1e57a2bd0db1414fa7d68ced.png</a></p>
  
  <p>I am not sure how to correctly take this library into use. Any help in this case, or should I make another question for it?</p>
  
  <p>EDIT:</p>
  
  <p>I added -lSDL2 to the linker options and deleted the other parameters. Now it builds fine:</p>
  
  <pre><code>mingw32-g++.exe -Wall -fexceptions  -g    -IC:\Users\User\Desktop\SDL2-2.0.0\include  -c "C:\Users\User\Desktop\CppProjects\SDL project\main.cpp" -o obj\Debug\main.o
  mingw32-g++.exe -Wall -fexceptions  -g    -IC:\Users\User\Desktop\SDL2-2.0.0\include  -c "C:\Users\User\Desktop\CppProjects\SDL project\thetestfile.cpp" -o obj\Debug\thetestfile.o
  mingw32-g++.exe -LC:\Users\User\Desktop\SDL2-2.0.0\build\.libs  -o "bin\Debug\SDL project.exe" obj\Debug\main.o obj\Debug\thetestfile.o   -lSDL2  ..\..\SDL2-2.0.0\build\.libs\libSDL2.a C:\Users\User\Desktop\SDL2-2.0.0\build\.libs\libSDL2.a  -mwindows
  Output size is 945.80 KB
  Process terminated with status 0 (0 minutes, 1 seconds)
  0 errors, 0 warnings (0 minutes, 1 seconds)
  </code></pre>
  
  <p>But when I try to run it, it says my computer lacks SDL2.dll, while the whole point was to static-link.</p>
  
  <p>So currently I have the path to build/.libs in my Link libraries -settings, -lSDL2 in the Other linker options, and for search directories I have the path to SDL2-2.0.0/include for the compiler and SDL2-2.0.0/build/.libs for the linker.</p>
  
  <p>In the build/.libs directory I can also see libSDL2.a, libSDL2.dll.a, libSDL2.la and libSDL2.lai files, which I don't know what they are.</p>