title: Link OpenCV library with Qt creator on ubuntu
body: <p>When I tried to link the OpenCV library on Ubuntu, some problems happened which I cannot understand.</p>
  
  <p>I used OpenCV 2.4.11 and Qt creator on Ubuntu 14.04.</p>
  
  <p>In my project file, I wrote</p>
  
  <pre><code>INCLUDEPATH += /usr/local/include/opencv
  INCLUDEPATH += /usr/local/include/opencv2
  
  LIBS += -L/usr/local/lib\
       -lopencv_calib3d\
       -lopencv_contrib\
       -lopencv_core\
       -lopencv_features2d \
       -lopencv_flann\
       -lopencv_gpu\
       -lopencv_highgui\
       -lopencv_imgproc\
       -lopencv_legacy\
       -lopencv_ml\
       -lopencv_nonfree\
       -lopencv_objdetect\
       -lopencv_ocl\
       -lopencv_photo\
       -lopencv_stitching\
       -lopencv_superres\
       -lopencv_ts\
       -lopencv_video\
       -lopencv_videostab
  </code></pre>
  
  <p>But there were many errors when building the project, such as <code>undefined reference to 'cvCreateMat'</code>. Obviously, the OpenCV wasn't linked to my project properly.</p>
  
  <p>Thus, I searched online and tried a possible solution, and that is </p>
  
  <pre><code>CONFIG += link_pkgconfig
  PKGCONFIG += opencv
  </code></pre>
  
  <p>To my surprise, it works and no linking errors again.</p>
  
  <p>However, I still cannot understand why it didn't work in the first way, since I have successfully set up my project in that way on Mac OS X. Why doesn't it work on my Ubuntu now? </p>
  
  <hr>
  
  <p>I tried <code>pkg-config --libs opencv</code>, the result was</p>
  
  <pre><code>-L/usr/local/lib -lopencv_calib3d -lopencv_contrib -lopencv_core -lopencv_features2d -lopencv_flann -lopencv_gpu -lopencv_highgui -lopencv_imgproc -lopencv_legacy -lopencv_ml -lopencv_nonfree -lopencv_objdetect -lopencv_ocl -lopencv_photo -lopencv_stitching -lopencv_superres -lopencv_ts -lopencv_video -lopencv_videostab -ltbb -lXext -lX11 -lICE -lSM -lGL -lGLU -lrt -lpthread -lm -ldl
  </code></pre>