title: How to fix Mujoco CmakeLists build error "/usr/bin/ld: cannot find -lglfw"?
body: <p>I'm trying to simulate physics of a robot with Mujoco in C++. Because the project is a part of a bigger workspace, I need to use cmake to build the executable. However, I cannot seem to properly link all the dependant libraries, so I cannot get rid of the error:</p>
  
  <pre><code>~: /usr/bin/ld: cannot find -lglfw
  </code></pre>
  
  <p>I did a bit of research on the web on how to properly set up Mujoco in CmakeLists, and found some examples <a href="http://www.mujoco.org/forum/index.php?threads/c-makefile-cmakelists-txt.3840/" rel="nofollow noreferrer">here</a>, <a href="http://www.mujoco.org/forum/index.php?threads/cmake-request.3361/" rel="nofollow noreferrer">here</a>, and <a href="https://github.com/atabakd/MuJoCo-Tutorials" rel="nofollow noreferrer">here</a>.</p>
  
  <p>I replicated the CmakeLists files from the examples above, but the error still persisted. Here are the relevant snippets from my files. I defined an environment variable <code>MUJOCO_PATH</code> to point to the Mujoco folder on my machine. Concretely <code>$HOME/.mujoco/mujoco200</code>.</p>
  
  <p>CmakeLists.txt</p>
  
  <pre><code>######################################################
  # define the include directory of all ${CATKIN_PKGS} #
  ######################################################
  include_directories(
      ${PROJECT_SOURCE_DIR}/include
      ${catkin_INCLUDE_DIRS}
      ${Eigen_INCLUDE_DIRS}
      $ENV{MUJOCO_PATH}/include
  )
  
  ########################################################
  # manage the creation of the libraries and executables #
  ########################################################
  set(USE_GL 1)
  
  link_directories($ENV{MUJOCO_PATH}/bin)
  
  #Finding main mujoco library
  if(${USE_GL})
      file(GLOB LIB_MUJOCO $ENV{MUJOCO_PATH}/bin/libmujoco[0-9][0-9][0-9].so)
  else()
      file(GLOB LIB_MUJOCO $ENV{MUJOCO_PATH}/bin/libmujoco[0-9][0-9][0-9]nogl.so)
  endif()
  #Showing mujoco library found
  message(STATUS "MuJoCo lib: " ${LIB_MUJOCO})
  
  add_subdirectory(src)
  </code></pre>
  
  <p>src/CmakeLists.txt</p>
  
  <pre><code>set(BIN_NAME mujoco_finger_test)
  
  add_executable(${BIN_NAME} ${BIN_NAME}.cpp)
  target_link_libraries(${BIN_NAME} ${LIB_MUJOCO})
  
  # Standard libraries for GL
  target_link_libraries(${BIN_NAME} GL GLU glut )
  
  # Additional libraries from mujoco package
  target_link_libraries(${BIN_NAME} libglew.so libglfw.so.3 libglewegl.so libglewosmesa.so)
  </code></pre>
  
  <p>Does anyone have an idea why this could be the case? Am I missing something from these examples?</p>
  
  <p>Thanks!</p>