title: Linking SDL2 - CLion - Ubuntu 16.04 - G++
body: <h1>Background info</h1>
  
  <p>As the title says, I am on Ubuntu 16.04 using CLion and G++, and I am unable to link SDL2. </p>
  
  <p>SDL2.h is found in the project at <code>External Libraries/Header Search Paths/include/SDL2</code>. This seems to link to <code>/usr/include/SDL2</code>.</p>
  
  <p>So, with the header file found, I can <code>#include &lt;SDL2/SDL.h&gt;</code> without any issues. Yet, when I try to make use of SDL2 with something like, <code>SDL_Init( SDL_INIT_EVERYTHING )</code>, I get an <code>undefined reference</code>.</p>
  
  <p>If I compile from terminal with <code>g++ main.cpp -lSDL2 -o test</code> I have no errors. But, if I compile from terminal with <code>g++ main.cpp -o test</code>, then I have the same error as CLion!</p>
  
  <h1>Question</h1>
  
  <p>How do I link SDL2 to Cmake? Did I add this flag <code>-lsdl2</code> to the CMake file correctly? If I added it properly, then what am I missing?</p>
  
  <h1>main.cpp</h1>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;SDL2/SDL.h&gt;
  
  int main(int argc, char* argv[]) {
      SDL_Init( SDL_INIT_EVERYTHING );
      std::cout &lt;&lt; "Hello, World!" &lt;&lt; std::endl;
      SDL_Quit();
      return 0;
  }
  </code></pre>
  
  <h1>CMakeLists.txt</h1>
  
  <pre><code>cmake_minimum_required(VERSION 3.12)
  project(untitled2)
  
  
  set(CMAKE_CXX_STANDARD 11)
  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -lSDL2")
  
  add_executable(untitled2 main.cpp)
  </code></pre>