title: OpenCV g++ undefined reference when compiling works in one machine but not in another
body: <p>I'm facing the apparently very typical undefined reference with OpenCV linking with g++. I'm running in two machines, both with opencv/2.3.14.6 installed, linux OS, same code to compile, using pkg-config. I checked 'pkg-config opencv --libs' and in both is the same result</p>
  <blockquote>
  <p>-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 -lrt -lpthread -lm -ldl</p>
  </blockquote>
  <p>The machine where it fails has CentOS Linux release 7.9.2009 (will call it centos machine), the one were compilation passes Linux version 4.19.0-9-amd64 (will call it debian machine).
  In my code, I use <code>#include &lt;opencv2/opencv.hpp&gt;</code>, which should include all opencv libs, however, I tried also including the specific libs, same result, debian machine all good, centos machine fails. I even tried running one of the examples from OpenCV documentation where most of the functions I get flagged are being used, got the same result. This is part of the error stack, same error goes for imread, imshow, namedwindow and videowriter, everything else seems fine:</p>
  <blockquote>
  <p>test.cpp:(.text+0x1af4): undefined reference to `cv::putText(cv::Mat&amp;, std::<em><em>cxx11::basic_string&lt;char, std::char_traits, std::allocator &gt; const&amp;, cv::Point</em>, int, double, cv::Scalar</em>, int, int, bool)'</p>
  </blockquote>
  <p>I checked and all those functions do exist in the libs being included, for example, putText is contained in opencv2/core/core.hpp</p>
  <blockquote>
  <p>CV_EXPORTS_W void putText( Mat&amp; img, const string&amp; text, Point org,
  int fontFace, double fontScale, Scalar color,
  int thickness=1, int lineType=8,
  bool bottomLeftOrigin=false );</p>
  </blockquote>
  <p>This is the command line I'm using to compile</p>
  <pre><code>g++ -Wall -std=c++11 -o test test.cpp `pkg-config --cflags --libs opencv`
  </code></pre>
  <p>Also tried this next one, just in case</p>
  <pre><code>g++ -Wall -std=c++11 -o test test.cpp `pkg-config opencv --cflags --libs`
  </code></pre>
  <p>And this</p>
  <pre><code>g++ -Wall -std=c++11 -o test test.cpp $(pkg-config opencv --cflags --libs)
  </code></pre>
  <p>Also tried replacing <code>pkg-config opencv --cflags --libs</code> with the direct libs list, still not able to compile in centos machine, and I do need to run in centos machine, but am unable to, most posts I've checked are solved with adding missing <code>pkg-config opencv --cflags --libs</code> to command line, code syntax error in files to compile, missing file or reinstalling opencv, but none of those help me. Also tried using different gcc versions as recommended <a href="https://stackoverflow.com/questions/32533206/opencv-undefined-reference-to-cvnamedwindow-linking-error">here</a>, but same result. I wonder if there is something else I can try or if I'm doomed to use debian machine (centos machine is an HPC machine, code takes a week to run in debian machine!).</p>
  <hr />
  <p>EDIT: for anyone having similar issues, see comments and check <a href="https://gcc.gnu.org/onlinedocs/libstdc++/manual/using_dual_abi.html" rel="nofollow noreferrer">dual ABI</a>, in my case, I was trying to use external libraries compiled with different gcc versions, solution is to ensure they are all compiled using compatible compiler versions.</p>