title: Compile with static libraries
body: <p>I am trying to compile two C++ projects with static libraries, with Eclipse C++ running at ubuntu 14.04.2. I have already achieved my purpose with the first one by writting the following command from terminal:</p>
  
  <blockquote>
    <p>g++ -o example main.cpp -static</p>
  </blockquote>
  
  <p>Now, if I write "ldd example", the answer I obtain is: "It is not a dynamical executable"</p>
  
  <p>However, the second project is using OpenCV (v 2.4.9) libraries. So, the previous command does not works to create a statical executable. I have also tried others such as:</p>
  
  <blockquote>
    <p>g++ -o example main.cpp -static <code>pkg-config --static --libs opencv</code> </p>
    
    <p>g++ -o example main.cpp <code>pkg-config --static --libs opencv</code></p>
  </blockquote>
  
  <p>But the first does not work (error in libcalib3d.so), and the second one creates the executable but with a lot of libraries dependences. Can anyone help me? If other information is needed please let me know and I will edit the post. Thank you!</p>
  
  <p>EDIT: 
  Writting in terminal this: pkg-config --static --libs opencv</p>
  
  <p>The output I obtain is the following:</p>
  
  <blockquote>
    <p>/usr/local/lib/libopencv_calib3d.so
    /usr/local/lib/libopencv_contrib.so /usr/local/lib/libopencv_core.so
    /usr/local/lib/libopencv_features2d.so
    /usr/local/lib/libopencv_flann.so /usr/local/lib/libopencv_gpu.so
    /usr/local/lib/libopencv_highgui.so
    /usr/local/lib/libopencv_imgproc.so /usr/local/lib/libopencv_legacy.so
    /usr/local/lib/libopencv_ml.so /usr/local/lib/libopencv_nonfree.so
    /usr/local/lib/libopencv_objdetect.so /usr/local/lib/libopencv_ocl.so
    /usr/local/lib/libopencv_photo.so
    /usr/local/lib/libopencv_stitching.so
    /usr/local/lib/libopencv_superres.so /usr/local/lib/libopencv_ts.a
    /usr/local/lib/libopencv_video.so
    /usr/local/lib/libopencv_videostab.so -lrt -lpthread -lm -ldl</p>
  </blockquote>
  
  <p>EDIT 2:
  The file opencv.pc contains the following lines</p>
  
  <blockquote>
    <p>prefix=/usr exec_prefix=${prefix}
    libdir=${prefix}/lib/x86_64-linux-gnu
    includedir_old=${prefix}/include/opencv
    includedir_new=${prefix}/include</p>
    
    <p>Name: OpenCV Description: Open Source Computer Vision Library Version:
    2.4.8 Libs: -L${libdir} ${exec_prefix}/lib/x86_64-linux-gnu/libopencv_calib3d.so
    -lopencv_calib3d ${exec_prefix}/lib/x86_64-linux-gnu/libopencv_contrib.so
    -lopencv_contrib ${exec_prefix}/lib/x86_64-linux-gnu/libopencv_core.so -lopencv_core ${exec_prefix}/lib/x86_64-linux-gnu/libopencv_features2d.so
    -lopencv_features2d ${exec_prefix}/lib/x86_64-linux-gnu/libopencv_flann.so -lopencv_flann
    ${exec_prefix}/lib/x86_64-linux-gnu/libopencv_gpu.so -lopencv_gpu
    ${exec_prefix}/lib/x86_64-linux-gnu/libopencv_highgui.so
    -lopencv_highgui ${exec_prefix}/lib/x86_64-linux-gnu/libopencv_imgproc.so
    -lopencv_imgproc ${exec_prefix}/lib/x86_64-linux-gnu/libopencv_legacy.so
    -lopencv_legacy ${exec_prefix}/lib/x86_64-linux-gnu/libopencv_ml.so -lopencv_ml ${exec_prefix}/lib/x86_64-linux-gnu/libopencv_objdetect.so -lopencv_objdetect ${exec_prefix}/lib/x86_64-linux-gnu/libopencv_ocl.so -lopencv_ocl
    ${exec_prefix}/lib/x86_64-linux-gnu/libopencv_photo.so -lopencv_photo
    ${exec_prefix}/lib/x86_64-linux-gnu/libopencv_stitching.so
    -lopencv_stitching ${exec_prefix}/lib/x86_64-linux-gnu/libopencv_superres.so
    -lopencv_superres ${exec_prefix}/lib/x86_64-linux-gnu/libopencv_ts.so -lopencv_ts ${exec_prefix}/lib/x86_64-linux-gnu/libopencv_video.so -lopencv_video ${exec_prefix}/lib/x86_64-linux-gnu/libopencv_videostab.so
    -lopencv_videostab Cflags: -I${includedir_old} -I${includedir_new}</p>
  </blockquote>