title: Linker can not find OpenCV libraries when using CMake
body: <p>I have a copy of OpenCV2.4.0 installed in /usr/local/lib</p>
  
  <p>My program compiled properly but when the linker is evoked, it gave errors such as:</p>
  
  <pre><code>/home/zhouw/moos-ivp-zhouw/trunk/src/pATRTest/mst.cpp:661: undefined reference to 'cv::_OutputArray::_OutputArray(cv::Mat const&amp;)'
  CMakeFiles/pATR.dir/mst.cpp.o:/home/zhouw/moos-ivp-zhouw/trunk/src/pATRTest/mst.cpp:675: more undefined references to `cv::_OutputArray::_OutputArray(cv::Mat const&amp;)' 
  collect2: ld returned 1 exit status
  make[2]: *** [../bin/pATR] Error 1
  make[1]: *** [src/pATRTest/CMakeFiles/pATR.dir/all] Error 2
  make: *** [all] Error 2
  </code></pre>
  
  <p>The strange thing is my program uses opencv intensively, if CMake has trouble finding the libraries, it should have complained a lot more undefined references than jsut a few. </p>
  
  <p>I tried adding 
  LINK_DIRECTORIES("/usr/local/lib") in my cmake file but it didn't help. 
  There's another library called POCO is also installed under /usr/local/lib. My program also links to the POCO libraries, but CMake seems having no trouble finding them. </p>
  
  <p>If I manually link with -L/usr/local/lib, it would link properly without error. </p>
  
  <p>The CMakeLists.txt looks like this</p>
  
  <pre><code>PROJECT(pATR)
  
  #what files are needed?
  SET(SRCS
  spline.hpp
  utils.hpp utils.cpp
  mst.hpp mst.cpp
  cluster.hpp cluster.cpp
  target.hpp target.cpp
  detector.hpp detector.cpp
  classifier.hpp classifier.cpp
  atr.hpp atr.cpp
  MOOSAtr.h MOOSAtr.cpp
  main.cpp
  )
  
  ADD_EXECUTABLE(pATR ${SRCS})
  
  # indicate how to link
  #LINK_DIRECTORIES("/usr/local/lib")
  TARGET_LINK_LIBRARIES(pATR opencv_core opencv_highgui opencv_imgproc MOOS)
  
  INSTALL(TARGETS
  pATR
  RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/bin
  )
  </code></pre>
  
  <p>Any idea what's going on? Many thanks!</p>