title: CMake fails to find library
body: <p>I have a project in CLion that uses CMake. I have added a list of directories using the <code>include_directories</code> command and although the IDE finds them properly and provides auto-complete and the includes seem to link properly, when I try to run the program I get errors of undefined references to all functions.</p>
  
  <p>Updated CMake file:</p>
  
  <pre><code>cmake_minimum_required(VERSION 3.9)
  project(Test C)
  
  set(CMAKE_C_STANDARD 11)
  set(C_LIBRARIES_DIR E:/Work\ Related\ General/C\ Projects/Libraries)
  
  # set paths (only needed on windows)
  if(${CMAKE_SYSTEM_NAME} STREQUAL "Windows")
    # where is the SDL2 development package copied to?
    set(SDL2_PATH "${C_LIBRARIES_DIR}/SDL2-2.0.8/i686-w64-mingw32")
  
    # add path do search path (windows requires ";" instead of ":" )
    set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${C_LIBRARIES_DIR}/SDL2")
  endif()
  
  find_package(SDL2 REQUIRED)
  
  include_directories(${SDL2_INCLUDE_DIR})
  
  add_executable(Test src/main.c)
  
  target_link_libraries(Test ${SDL2_LIBRARY})
  </code></pre>
  
  <p>And the error I'm getting is the following:</p>
  
  <pre><code>"C:\Program Files\JetBrains\CLion 2017.3\bin\cmake\bin\cmake.exe" --build "E:\Work Related General\C Projects\Test\cmake-build-debug" --target Test -- -j 2
  [ 25%] Linking C executable Test.exe
  c:/mingw/bin/../lib/gcc/mingw32/6.3.0/../../../libmingw32.a(main.o):(.text.startup+0xa0): undefined reference to `WinMain@16'
  collect2.exe: error: ld returned 1 exit status
  mingw32-make.exe[3]: *** [Test.exe] Error 1
  CMakeFiles\Test.dir\build.make:152: recipe for target 'Test.exe' failed
  mingw32-make.exe[2]: *** [CMakeFiles/Test.dir/all] Error 2
  CMakeFiles\Makefile2:66: recipe for target 'CMakeFiles/Test.dir/all' failed
  mingw32-make.exe[1]: *** [CMakeFiles/Test.dir/rule] Error 2
  CMakeFiles\Makefile2:78: recipe for target 'CMakeFiles/Test.dir/rule' failed
  mingw32-make.exe: *** [Test] Error 2
  Makefile:117: recipe for target 'Test' failed
  </code></pre>
  
  <p>I can never find good help regarding CMake online and the fact that the IDE properly recognizes the libraries but fails to link baffles me since CLion and CMake should be taking care of that... What am I missing?</p>
  
  <p><strong>UPDATE</strong>
  Adding the following directive <strong>before</strong> the SDL include allowed gcc to properly link: <code>#define SDL_MAIN_HANDLED</code></p>
  
  <p>From what I read, SDL.h itself redefines the <code>main</code> function to <code>SDL_main</code> inside its header file. Adding this directive undefines it (sort of). The goal however is to make the program run without this (since this directive is for command line programs). Still no clue there...</p>