title: cmake -> libpthread.so.0: error adding symbols: DSO missing from command line
body: <p>I am getting the error</p>
  
  <pre><code>/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/7/../../../../lib/libgtest.a(gtest-all.cc.o): undefined reference to symbol 'pthread_key_delete@@GLIBC_2.2.5'
  /lib/x86_64-linux-gnu/libpthread.so.0: error adding symbols: DSO missing from command line
  collect2: error: ld returned 1 exit status
  </code></pre>
  
  <p>in a project built via <code>cmake</code>.
  The actual command line generating that error is (I am copying only the relevant part)</p>
  
  <pre><code>/usr/bin/c++  ...  -lpthread -ldl -Wl,-Bstatic -lgtest -Wl,-Bdynamic ...
  </code></pre>
  
  <p>The error means that <code>-lpthread</code> should go after <code>-lgtest</code>.</p>
  
  <p>After fixing that by hand, another error prompts me to moving <code>-lpthread</code> after <code>-Wl,-Bdynamic</code>. 
  After that change, linking works ok with</p>
  
  <pre><code>/usr/bin/c++  ...  -ldl -Wl,-Bstatic -lgtest -Wl,-Bdynamic -lpthread ...
  </code></pre>
  
  <p>But I did this by hand at the command line.</p>
  
  <p><strong>How should I modify my cmake configuration (either in <code>CMakeLists.txt</code> for my project, or elsewhere) to get the correct order of flags or remove the error?</strong></p>
  
  <p><hr>
  <strong>Note</strong>:
  Trying to find out where can this be set, I ran</p>
  
  <pre><code>$ find . -type f -iname "*cmake*" -exec grep -B 4 -A 4 pthread {} \;
  </code></pre>
  
  <p>at the root of my project.
  There is only one instance reported in <code>./CMake/FindMyprojMKL.cmake</code></p>
  
  <pre><code>  set(MKL_LIBS
  #      mkl_solver_lp64
        mkl_intel_lp64
        mkl_core
        pthread
        mkl_gnu_thread)
    message(STATUS "MKL_LIBS= ${MKL_LIBS}")
  ELSE(MKL_LIBRARY)
    message(STATUS "Error: can not found MKL_LIBRARY")
  </code></pre>
  
  <p>I guess this is not the right place to fix the issue.</p>