title: linking GLEW with MinGW64 - undefined reference to `__imp_glewExperimental' and `__imp___glewGenVertexArrays'
body: <blockquote>
    <p>undefined reference to '[various things from GLEW library]'</p>
  </blockquote>
  
  <p>This is my CMakeLists.txt:</p>
  
  <pre><code>cmake_minimum_required(VERSION 3.7)
  project(newerOpenGLTest)
  
  set(CMAKE_CXX_STANDARD 11)
  
  set(SOURCE_FILES main.cpp)
  add_executable(newerOpenGLTest ${SOURCE_FILES})
  
  find_package(OpenGL)
  
  # tell it where to look for glew
  set(CMAKE_PREFIX_PATH "F:/glew-2.0.0")
  set(CMAKE_LIBRARY_PATH "F:/glew-2.0.0/lib/Release/x64")
  
  find_package(GLEW REQUIRED)
  
  if (GLEW_FOUND)
      message(${GLEW_INCLUDE_DIRS})
      message(${GLEW_LIBRARIES})
  
      # Detect and add SFML
      set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake_modules" ${CMAKE_MODULE_PATH})
      #Find any version 2.X of SFML
      #See the FindSFML.cmake file for additional details and instructions
      find_package(SFML 2 REQUIRED graphics window system)
  
      if(SFML_FOUND)
          include_directories(
                  ${GLEW_INCLUDE_DIRS}
                  ${SFML_INCLUDE_DIR}
          )
          target_link_libraries(
                  newerOpenGLTest
                  ${GLEW_LIBRARIES}
                  ${SFML_LIBRARIES}
                  ${SFML_DEPENDENCIES}
                  ${OPENGL_gl_LIBRARY}
          )
      endif()
  
  endif()
  </code></pre>
  
  <p>This is the output from Cmake:</p>
  
  <pre><code>F:/glew-2.0.0/include
  F:/glew-2.0.0/lib/Release/x64/glew32.lib
  -- Found SFML 2.4.2 in F:/SFML-2.4.2 for GCC 6.1.0 MinGW (SEH) - 64-bit/include
  -- Configuring done
  -- Generating done
  -- Build files have been written to: F:/Users/Doug/CLionProjects/newerOpenGLTest/cmake-build-debug
  </code></pre>
  
  <p>Everything looks fine to me there. It finds GLEW and finds locations for the include files and libraries.</p>
  
  <p>Here is my main.cpp:</p>
  
  <pre><code>#include &lt;GL/glew.h&gt;
  
  #include &lt;SFML/Window.hpp&gt;
  
  int main() {
      sf::Window window(sf::VideoMode(800, 600), "openGL");
      window.setVerticalSyncEnabled(true);
      window.setActive(true);
  
      // Initialize GLEW
      glewExperimental = true;
      if (glewInit() != GLEW_OK) {
          fprintf(stderr, "Failed to initialize GLEW\n");
          return -1;
      }
  
      GLuint VertexArrayID;
      glGenVertexArrays(1, &amp;VertexArrayID);
      glBindVertexArray(VertexArrayID);
  
      bool running = true;
      while (running) {
          sf::Event event;
          while (window.pollEvent(event)) {
              if (event.type == sf::Event::Closed) {
                  running = false;
              }
          }
      }
      return 0;
  }
  </code></pre>
  
  <p>Here is the output from linking:</p>
  
  <pre><code>Linking CXX executable newerOpenGLTest.exe
  CMakeFiles\newerOpenGLTest.dir\build.make:100: recipe for target 'newerOpenGLTest.exe' failed
  CMakeFiles\Makefile2:66: recipe for target 'CMakeFiles/newerOpenGLTest.dir/all' failed
  CMakeFiles\Makefile2:78: recipe for target 'CMakeFiles/newerOpenGLTest.dir/rule' failed
  Makefile:117: recipe for target 'newerOpenGLTest' failed
  CMakeFiles\newerOpenGLTest.dir/objects.a(main.cpp.obj): In function `main':
  main.cpp:xx: undefined reference to `__imp_glewExperimental'
  main.cpp:xx: undefined reference to `__imp___glewGenVertexArrays'
  main.cpp:xx: undefined reference to `__imp___glewBindVertexArray'
  collect2.exe: error: ld returned 1 exit status
  mingw32-make.exe[3]: *** [newerOpenGLTest.exe] Error 1
  mingw32-make.exe[2]: *** [CMakeFiles/newerOpenGLTest.dir/all] Error 2
  mingw32-make.exe[1]: *** [CMakeFiles/newerOpenGLTest.dir/rule] Error 2
  mingw32-make.exe: *** [newerOpenGLTest] Error 2
  </code></pre>
  
  <p>Undefined reference to 3 GLEW elements.</p>
  
  <p>Notice that it does not say <code>undefined reference to '__imp_glewInit'</code></p>
  
  <p>So it is linking some of GLEW, but not everything.</p>
  
  <p>I run <code>glewinfo.exe</code> and the output has <code>glGenVertexArrays: OK</code>
  I think that means my driver supports that function.</p>