title: C++ with Qt compile fail
body: <p>I'm trying to compile the following short C++ program (not written by me) in Debian:</p>
  
  <pre><code>$ cat checksig.cpp
  #include &lt;QByteArray&gt;
  #include &lt;QDebug&gt;
  
  #include &lt;openssl/ec.h&gt;
  #include &lt;openssl/evp.h&gt;
  #include &lt;openssl/ecdsa.h&gt;
  #include &lt;openssl/sha.h&gt;
  
  static EC_KEY* EC_KEY_pub_key ( const QByteArray&amp; pub )
  {
    static EC_KEY* eckey = EC_KEY_new_by_curve_name ( NID_secp256k1 );
    const quint8* ppub = (const quint8*)pub.constData ( );
    o2i_ECPublicKey ( &amp;eckey, &amp;ppub, pub.size ( ) );
    return eckey;
  }
  //--------------------------------------------------------------
  int main(int argc, char *argv[])
  {
    const QByteArray data ( QByteArray::fromHex ( argv [1] ) );
    const QByteArray sign ( QByteArray::fromHex ( argv [2] ) );
    const QByteArray pubk ( QByteArray::fromHex ( argv [3] ) );
  
    quint8 tmp [32];
    ::SHA256 ( (const quint8*)data.constData ( ), data.size ( ), tmp );
    quint8 digest [32];
    ::SHA256 ( tmp, 32, digest );
    qDebug ( ) &lt;&lt; "data=" &lt;&lt; QString ( data.toHex ( ) );
    qDebug ( ) &lt;&lt; "sign=" &lt;&lt; QString ( sign.toHex ( ) );
    qDebug ( ) &lt;&lt; "pubk=" &lt;&lt; QString ( pubk.toHex ( ) );
  
    qDebug ( ) &lt;&lt; "digest=" &lt;&lt; QString ( QByteArray ( (const char*)digest, 32 ).toHex ( ) );
  
    const bool v ( ::ECDSA_verify ( 0, digest, 32, (const quint8*)sign.constData ( ), sign.size ( ), EC_KEY_pub_key ( pubk ) ) );
    qDebug ( ) &lt;&lt; "result=" &lt;&lt; v;
  
    return 0;
  }
  </code></pre>
  
  <p>But I don't think I'm using the right includes, or maybe I need to install more Qt libraries?</p>
  
  <pre><code>$ g++ -Wall checksig.cpp -o checksig -L /usr/include/i386-linux-gnu/qt5/QtCore/ -lQtCore -I /usr/include/i386-linux-gnu/qt5/QtCore/
  In file included from /usr/include/i386-linux-gnu/qt5/QtCore/QByteArray:1:0,
  from checksig.cpp:4:/usr/include/i386-linux-gnu/qt5/QtCore/qbytearray.h:45:30: fatal error: QtCore/qrefcount.h: No such file or directory
  #include &lt;QtCore/qrefcount.h&gt;
                               ^
  </code></pre>
  
  <p>and alternatively, using includes and libraries from one directory back:</p>
  
  <pre><code>g++ -Wall checksig.cpp -o checksig -L /usr/include/i386-linux-gnu/qt5/ -lQtCore -I /usr/include/i386-linux-gnu/qt5/
  checksig.cpp:4:22: fatal error: QByteArray: No such file or directory
  #include &lt;QByteArray&gt;
                        ^
  compilation terminated.
  </code></pre>
  
  <p>I'm new to C++. How can I compile this small program in a 1-liner?</p>
  
  <hr>
  
  <p>As requested in the comments:</p>
  
  <pre><code>$ sudo apt-file search "QtCore/qrefcount.h"
  qtbase5-dev: /usr/include/i386-linux-gnu/qt5/QtCore/qrefcount.h
  </code></pre>
  
  <hr>
  
  <p>thanks to <a href="https://stackoverflow.com/users/4762451/michael-popovich">Michael Popovich</a>'s answer i tried the following and got further. but now i have new errors:</p>
  
  <pre><code>$ g++ -Wall checksig.cpp -o checksig -L /usr/include/i386-linux-gnu/qt5/QtCore/ -lQtCore -I /usr/include/i386-linux-gnu/qt5/ -I /usr/include/i386-linux-gnu/qt5/QtCore/
  In file included from /usr/include/i386-linux-gnu/qt5/QtCore/qatomic.h:42:0,
                   from /usr/include/i386-linux-gnu/qt5/QtCore/qrefcount.h:45,
                   from /usr/include/i386-linux-gnu/qt5/QtCore/qbytearray.h:45,
                   from /usr/include/i386-linux-gnu/qt5/QtCore/QByteArray:1,
                   from checksig.cpp:4:
  /usr/include/i386-linux-gnu/qt5/QtCore/qglobal.h:1034:4: error: #error "You must build your code with position independent code if Qt was built with -reduce-relocations. " "Compile your code with -fPIC or -fPIE."
   #  error "You must build your code with position independent code if Qt was built with -reduce-relocations. "\
      ^
  </code></pre>
  
  <p>i have no idea if qt was built with <code>-reduce-relocations</code> i don't think i even installed it myself - it was probably pulled in as a dependency for another install.</p>
  
  <p>anyway, trying with <code>-fPIC</code> and <code>-fPIE</code>:</p>
  
  <pre><code>$ g++ -Wall checksig.cpp -o checksig -L /usr/include/i386-linux-gnu/qt5/QtCore/ -lQtCore -I /usr/include/i386-linux-gnu/qt5/ -I /usr/include/i386-linux-gnu/qt5/QtCore/ -fPIC
  /usr/bin/ld: cannot find -lQtCore
  collect2: error: ld returned 1 exit status
  $ g++ -Wall checksig.cpp -o checksig -L /usr/include/i386-linux-gnu/qt5/QtCore/ -lQtCore -I /usr/include/i386-linux-gnu/qt5/ -I /usr/include/i386-linux-gnu/qt5/QtCore/ -fPIE
  /usr/bin/ld: cannot find -lQtCore
  collect2: error: ld returned 1 exit status
  </code></pre>