title: Minimal example with GLFW fails because of undefined symbols for architecture x86_64
body: <p>I am trying to compile the following minimal example for <code>GLFW</code>:</p>
  
  <pre><code>#include &lt;GLFW/glfw3.h&gt;
  #include &lt;thread&gt;
  
  int main() {
      glfwInit();
      std::this_thread::sleep_for(std::chrono::seconds(1));
      glfwTerminate();
      return 0;
  }
  </code></pre>
  
  <p>My <code>CMakeLists.txt</code> file is:</p>
  
  <pre><code>cmake_minimum_required(VERSION 3.9)
  project(viewer)
  
  set(CMAKE_CXX_STANDARD 11)
  
  find_package(glfw3 3.2 REQUIRED)
  include_directories(${GLFW_INCLUDE_DIRS})
  
  add_executable(viewer main.cpp)
  
  target_link_libraries(viewer ${GLFW_LIBRARIES})
  </code></pre>
  
  <p>If I try to compile the code, it fails with the following error message:</p>
  
  <pre><code>[ 50%] Linking CXX executable visualiser
  Undefined symbols for architecture x86_64:
    "_glfwInit", referenced from:
        _main in main.cpp.o
    "_glfwTerminate", referenced from:
        _main in main.cpp.o
  ld: symbol(s) not found for architecture x86_64
  clang: error: linker command failed with exit code 1 (use -v to see invocation)
  make[3]: *** [visualiser] Error 1
  make[2]: *** [CMakeFiles/visualiser.dir/all] Error 2
  make[1]: *** [CMakeFiles/visualiser.dir/rule] Error 2
  make: *** [visualiser] Error 2
  </code></pre>
  
  <p>I see the similar questions, e.g.:</p>
  
  <ul>
  <li><a href="https://stackoverflow.com/questions/43817344/trouble-compiling-glfw-undefined-symbols">Trouble compiling GLFW, undefined symbols</a></li>
  <li><a href="http://dudandan.com/2017/02/15/Setup-glfw-and-glew/" rel="nofollow noreferrer">http://dudandan.com/2017/02/15/Setup-glfw-and-glew/</a></li>
  </ul>
  
  <p>But their solutions did not really help.</p>
  
  <p><strong>UPD:</strong> Following the comment of @thomas_f, I modified my <code>CMakeLists.txt</code> file as follows:</p>
  
  <pre><code>cmake_minimum_required(VERSION 3.9)
  project(viewer)
  
  set(CMAKE_CXX_STANDARD 11)
  
  find_package(glfw3 3.2 REQUIRED)
  include_directories(${GLFW3_INCLUDE_DIR})
  
  add_executable(viewer main.cpp)
  
  target_link_libraries(viewer ${GLFW3_LIBRARY})
  message(GLFW LIB: ${GLFW3_LIBRARY})
  </code></pre>
  
  <p>I also made sure that there is no <code>CMakeCache.txt</code> in my build directory:</p>
  
  <pre><code>$ ls -a
  .                 ..                .idea             CMakeLists.txt    cmake-build-debug main.cpp
  </code></pre>
  
  <p>However, I still get the same error message. It seems, that </p>
  
  <pre><code>/Applications/CLion.app/Contents/bin/cmake/bin/cmake -DCMAKE_BUILD_TYPE=Debug -G "CodeBlocks - Unix Makefiles" ........./viewer
  GLFWLIB:
  -- Configuring done
  -- Generating done
  -- Build files have been written to: /Users/denis/Documents/projects/theia/code/visualiser/cmake-build-debug
  
  [Finished]
  </code></pre>
  
  <p>So it seems that <code>${GLFW3_LIBRARY}</code> is not defined.</p>