title: Win7 MInGW QT MySQL program screams "cannot find -lqsqlmysqld"; where is the missing library?
body: <p>I am attempting to make a qt program on Windows 7 that uses a MySQL plugin.</p>
  
  <p>I have compiled both qt and the mysql plugin with no problems using my minGW 32bit compiler.</p>
  
  <p>However, I keep on getting an error like this:</p>
  
  <pre><code>mingw32-make -f Makefile.Debug
  mingw32-make[1]: Entering directory `C:/Users/dhatt/Desktop/testdb2'
  g++ -c -g -frtti -fexceptions -mthreads -Wall -DUNICODE -DQT_LARGEFILE_SUPPORT -DQT_DLL -DQT_SQL_LIB -DQT_GUI_LIB -DQT_CORE_LIB -DQT_THREAD_SUPPORT -DQT_NEEDS_QMAIN -    I"..\..\..\..\QT\qt\include\QtCore" -I"..\..\..\..\QT\qt\include\QtGui" -I"..\..\..\..\QT\qt\include\QtSql" -I"..\..\..\..\QT\qt\include" -I"..\..\..\..\MySQL\bin" -I"..\..\..\..\QT\qt\include\ActiveQt" -I"debug" -I"..\..\..\..\QT\qt\mkspecs\win32-g++" -o debug\database.o database.cpp
  g++ -enable-stdcall-fixup -Wl,-enable-auto-import -Wl,-enable-runtime-pseudo-reloc -mthreads -Wl -Wl,-subsystem,windows -o debug\testdb2.exe debug/database.o  -L"c:\QT\qt\lib" -lmingw32 -lqtmaind -L C:\MySQL\lib\opt -LC:/QT/qt/plugins/sqldrivers -lqsqlmysqld -lQtSqld4 -lQtGuid4 -lQtCored4 -LC:\MySQL\lib\opt
  C:/qt/mingw/bin/../lib/gcc/mingw32/4.4.0/../../../../mingw32/bin/ld.exe: cannot find -lqsqlmysqld
  collect2: ld returned 1 exit status
  mingw32-make[1]: *** [debug\executable.exe] Error 1
  mingw32-make[1]: Leaving directory `C:/Users/dhatt/Desktop/testdb2'
  mingw32-make: *** [debug] Error 2
  </code></pre>
  
  <p>I apologize in advance for being very verbose of what I did, but I am doing this partly for troubleshooting, and partly so any other lost souls don't end up wasting three weeks on this particular problem. :)</p>
  
  <p>Here are my specs:</p>
  
  <pre><code>Windows 7 Nokia's Open Source QT
  Qt SDK for Windows (C:\Qt\2010.04\qt)
  Linux MinGW Version 5.1.6 (C\Linux\MinGW)
  MySQL5 with C++ files (C:\MySQL5)
  </code></pre>
  
  <p>If you want to know how I installed qt, just follow this site's instructions:</p>
  
  <p><a href="http://www.jiggerjuice.net/software/qt-sql-drivers.html" rel="nofollow noreferrer">http://www.jiggerjuice.net/software/qt-sql-drivers.html</a></p>
  
  <p>These other sites may hold some extra information tidbits:</p>
  
  <p><a href="http://doc.qt.nokia.com/4.6/sql-driver.html" rel="nofollow noreferrer">http://doc.qt.nokia.com/4.6/sql-driver.html</a> </p>
  
  <p><a href="http://www.rag.com.au/linux/qt4howto.html" rel="nofollow noreferrer">http://www.rag.com.au/linux/qt4howto.html</a> </p>
  
  <p><a href="http://qtnode.net/wiki?title=Qt4_on_Windows" rel="nofollow noreferrer">http://qtnode.net/wiki?title=Qt4_on_Windows</a> (yes, I did check with Nokia's docs!!!) </p>
  
  <p><a href="http://doc.trolltech.com/qq/qq10-windows-deployment.html" rel="nofollow noreferrer">http://doc.trolltech.com/qq/qq10-windows-deployment.html</a> </p>
  
  <p>This fellow mentioned about remaking qmake, which I am not doing unless I have a good reason.</p>
  
  <p><a href="http://christopher.rasch-olsen.no/2009/04/14/qt-45-and-mysql-plugin-with-mingw-on-windows-xp/" rel="nofollow noreferrer">http://christopher.rasch-olsen.no/2009/04/14/qt-45-and-mysql-plugin-with-mingw-on-windows-xp/</a></p>
  
  <p>I've already deleted the plugin cache once before, I hope I won't have to do it again...</p>
  
  <p><a href="http://doc.trolltech.com/4.2/plugins-howto.html#the-plugin-cache" rel="nofollow noreferrer">http://doc.trolltech.com/4.2/plugins-howto.html#the-plugin-cache</a></p>
  
  <p><a href="http://ubuntuforums.org/showthread.php?t=1070155" rel="nofollow noreferrer">http://ubuntuforums.org/showthread.php?t=1070155</a></p>
  
  <p>If there is any confusion, between the two compilation option (creating the mysql libraries statically, or as a plugin), I chose for the plugin because it compiles quicker and I don't have to worry about licensing.</p>
  
  <p>Generally, the big trouble of mysql to most people is to make a mingw compatible library.  Generally, I did this with the mingw tools in ( <a href="https://olex.openlogic.com/packages/mingw-utils" rel="nofollow noreferrer">https://olex.openlogic.com/packages/mingw-utils</a> )...</p>
  
  <pre><code>c:\&gt; cd MySQL\lib\opt
  c:\mysql\lib\opt&gt; reimp -d libmysql.lib
  c:\mysql\lib\opt&gt; dlltool --input-def libmysql.def --dllname libmysql.dll --output-lib libmysql.a -k
  </code></pre>
  
  <p>I should have done it right since in my C:\MySQL\lib\opt, it has the two files:</p>
  
  <pre><code>libmysql.a
  libmysql.lib
  LIBMYSQL.def   (not a typo)
  </code></pre>
  
  <p>and in the C:\MySQL\bin directory, I have:</p>
  
  <pre><code>libmySQL.bin    (not a typo)
  </code></pre>
  
  <p>I had compiled the mysql plugin beforehand:</p>
  
  <pre><code>cd %QTDIR%\src\plugins\sqldrivers\mysql
  qmake "INCLUDEPATH+=C:\MySQL\include" "LIBS+=C:\MYSQL\lib\opt\libmysql.lib" mysql.pro
  mingw32-make
  </code></pre>
  
  <p>As a result, I have in my C:\QT\qt\plugins\sqldrivers folder:</p>
  
  <pre><code>libqsqlmysql4.a
  libqsqlmysqldq4.a
  libqsqlodbc4.a
  libqsqlodbcd4.a
  qsqlmysql4.dll
  qsqlmysqld4.dll
  qsqlodbc4.dll
  qsqlodbc4.dll
  </code></pre>
  
  <p>And in my C:\QT\bin folder</p>
  
  <pre><code>QtSql4.dll
  QtSqld4.dll
  </code></pre>
  
  <p>So, I assume from this site ( <a href="http://www.qtforum.org/article/21352/how-to-compile-use-a-mysql-driver.html" rel="nofollow noreferrer">http://www.qtforum.org/article/21352/how-to-compile-use-a-mysql-driver.html</a>) that I got it right.</p>
  
  <p>I didn't use the binaries of qt itself, I used the compiled qt files(also from Nokia), but reconfigured and recompiled them using mingw32-make.  I had no errors.  This was my configuration options for remaking qt.</p>
  
  <pre><code>-opensource
  -nomake examples
  -nomake demos
  -no-sql-lite
  -no-qt3support
  -no-gif
  -no-libpng
  -no-libmng
  -no-libtiff
  -no-phonon
  -no-phonon-backend
  -no-multimedia
  -no-audio-backend
  -no-webkit
  -no-script
  -no-scripttools
  -nodeclarative
  -plugin-sql-mysql -l mysql -I C:\QT\qt\include -L C:\QT\qt\lib\opt
  </code></pre>
  
  <p>Here is my .pro file </p>
  
  <pre><code>LANGUAGE = C++
  
  TEMPLATE = app
  TARGET = executable
  QT += core sql
  QTPLUGIN += qsqlmysql
  DEPENDPATH += .
  INCLUDEPATH += C:\MySQL\bin
  LIBS += -L C:\MySQL\lib\opt -lmysql
  
  # Input
  SOURCES += database.cpp
  </code></pre>
  
  <p>I installed the plugin described in here:</p>
  
  <pre><code>C:\QT\qt
  </code></pre>
  
  <p>My path variables are:</p>
  
  <pre><code>%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\QuickTime\QTSystem\;C:\Python26;C:\Linux\Cygwin\bin;C:\mingw-utils-0.3\bin;C:\QT\qt\bin;C:\MySQL\bin;C:\MySQL\include;C:\QT\mingw32\bin;C:\QT\mingw\bin;C:\QT\qt\plugins\sqldrivers
  </code></pre>
  
  <p>The qt command prompt added a few extra though, so I did all of this in the command prompt.</p>
  
  <pre><code>Setting up a MinGW/Qt only environment...
  -- QTDIR set to C:\QT\qt
  -- PATH set to C:\QT\qt\bin
  -- Adding C:\QT\bin to PATH
  -- Adding C:\Windows\System32 to PATH
  -- QMAKESPEC set to win32-g++ (mingw is my only compiler so, this is unnecessary)
  </code></pre>
  
  <p>Although I either did all that already, or it is redundant.  I only add this for the sake of completeness.</p>
  
  <p>Here is my code (database.cpp):</p>
  
  <pre><code>#include &lt;QtSql&gt;
  #include &lt;iostream&gt;
  using namespace std;
  
  int main( int argc, char ** argv )
  {
      QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
      db.setHostName("---.---.---.---");
      db.setDatabaseName("--------");
      db.setUserName("------------");
      db.setPassword("------------");
      if (!db.open()) cout &lt;&lt; "Failed to connect to mysql" &lt;&lt; endl;
      else cout &lt;&lt; "Works finally." &lt;&lt; endl;
      QSqlDatabase::removeDatabase("QMYSQL");
      exit ( 0 );
  }
  </code></pre>
  
  <p>Very simple, yes?</p>
  
  <p>I went to my directory with the example code, run</p>
  
  <pre><code>mingw32-make distclean
  qmake
  mingw32-make
  </code></pre>
  
  <p>and get the error message above.  I've tried building a version with the release version only (no debug), and it still shows the same message, but with "cannot find -lqsqlmysq", so it is not that.</p>
  
  <p>I've tried many things, but where should I look next to solve it; maybe someone can narrow it down for me, set me on the right path, or even better, solve his annoying problem.</p>
  
  <p>Also, I plan to use python bindings with my code (I need PyQT + MySQL).  If the proposed solution would prevent me from doing so, let me know.</p>