mysqlqtqtsql

undefined reference to symbol '_ZN12QSqlDatabase11setHostNameERK7QString'


My program has a basic function for adding datas to database but when the code gives an error when it is compiled.

void MainWindow::AddLocationToDatabase()
{
    QSqlDatabase db= QSqlDatabase::addDatabase("QMYSQL");
    db.setHostName("localhost");
    db.setUserName("root");
    db.setPassword("*******");
    db.setDatabaseName("databasename");
    db.setPort(1111);

    if(db.open()){
          qDebug()<<"connected";
    }

}

/usr/bin/ld: build/debug/mainwindow.o: undefined reference to symbol '_ZN12QSqlDatabase11setHostNameERK7QString'

/usr/lib/x86_64-linux-gnu/libQt5Sql.so.5: error adding symbols: DSO missing from command line collect2: error: ld returned 1 exit status make: *** [sub-pcapprogram-make_first-ordered] Error 2 06:57:04: The process "/usr/bin/make" exited with code 2. When executing step "Make"


Solution

  • When I added "QT += sql", there was no error.