title: Qt embedding MYSQL
body: <p>This Question has been asked by different people about 3times by <a href="https://stackoverflow.com/users/425104/qlands">QLands</a>: <a href="https://stackoverflow.com/questions/8364157/use-mysql-embedded-with-qt/34727524">here</a> and <a href="https://stackoverflow.com/users/2459321/carnifrex">carnifrex</a>: <a href="https://stackoverflow.com/questions/18092724/c-qt-embedded-mysql-server?noredirect=1&amp;lq=1">here</a> and <a href="https://stackoverflow.com/questions/16990142/qt-c-embedded-mysql?rq=1">there</a>. My problem is exactly like <a href="https://stackoverflow.com/questions/16990142/qt-c-embedded-mysql?rq=1">carnifrex's</a>: I am trying to compile my application to connect to MYSQL(Mariadb) database without Mariadb installation i.e embedded server but I get this Error Below:</p>
  
  <p><code>error: undefined reference to 'imp__ZN12QMYSQLDriverC1EP8st_mysqlP7QObject' collect2.exe:-1: error: error: ld returned 1 exit status</code></p>
  
  <p>Unfortunately, <a href="https://stackoverflow.com/users/2459321/carnifrex">carnifrex</a> was not replied. Here's my Code</p>
  
  <p>main.cpp:</p>
  
  <pre><code>#include "mainwindow.h"
  
  #include &lt;QApplication&gt;
  #include &lt;QSql&gt;
  #include &lt;QMessageBox&gt;
  
  #include "qsql_mysql.h"
  #include &lt;mysql.h&gt;
  
  bool createConnection(QMYSQLDriver *drver)
  {
      QSqlDatabase db = QSqlDatabase::addDatabase(drver);
      db.setHostName("localhost");
      db.setDatabaseName("exama");
      db.setPort(3306);
      db.setUserName("root");
      db.setPassword("Adm1n16");
  
      if (!db.open()) {
          QMessageBox::warning(0, QObject::tr("Database Error"),
                               db.lastError().text());
          return false;
      }
      return true;
  }
  int main(int argc, char *argv[])
  {
      QApplication a(argc, argv);
      MYSQL *mysql;
  
      static char *server_options[] = \
      {"mysql_test", "--defaults-file = C:/Program Files (x86)/MariaDB 10.1/data/my.cnf", NULL };
      int num_elements = (sizeof(server_options) / sizeof(char *)) - 1;
  
      static char *server_groups[] = { "embedded", NULL };
  
      qDebug() &lt;&lt; "Loading embedded";
      mysql_library_init(num_elements, server_options, server_groups);
      mysql = mysql_init(NULL);
      mysql_options(mysql, MYSQL_READ_DEFAULT_GROUP, "embedded");
      mysql_options(mysql, MYSQL_OPT_USE_EMBEDDED_CONNECTION, NULL);
  
      mysql_real_connect(mysql, NULL,NULL,NULL, "database1", 0,NULL,0);
  
      QMYSQLDriver *drv = new QMYSQLDriver(mysql);
  
      if (!createConnection(drv))
          return 1;
      MainWindow w;
      w.show();
  
      return a.exec();
  
  }
  </code></pre>
  
  <p>mysqlConnect.pro:</p>
  
  <pre><code>QT+=core gui sql\
          widgets \
  
  greaterThan(QT_MAJOR_VERSION, 5): QT += widgets
  
  INCLUDEPATH += "C:\Qt\Qt5.4\5.4\mingw491_32\include\QtSql\5.4.0\QtSql\private"
  INCLUDEPATH += "C:\Program Files (x86)\MariaDB 10.1\include\mysql"
  
  QMAKE_LIBDIR += "C:\Program Files (x86)\MariaDB 10.1\lib"
  
  LIBS += -lmysql
  
  TARGET = mySQLConnect
  TEMPLATE = app
  
  SOURCES += main.cpp\
          mainwindow.cpp
  
  HEADERS  += mainwindow.h
  
  FORMS    += mainwindow.ui
  
  QMAKE_CXXFLAGS+=-std=c++11
  </code></pre>
  
  <p>The compilation fails at this line in main.cpp:</p>
  
  <pre><code>QMYSQLDriver *drv = new QMYSQLDriver(mysql);
  </code></pre>
  
  <p>I am using Qt Creator 5.4.0 with MingW 4.9.1 32bit on x64 bit Windows 7 Machine. I will be grateful for any assistance granted. </p>