QODBC su Linux Ubuntu 17.04
-
Ho disperatamente bisogno di un consiglio..
Sto cercando (invano) di far funzionare l'applicazione che ho sviluppato su windows su un sistema linux. A dire il vero va tutto tranne la comunicazione con il DB. Sfortunatamente il DB è un maledettissimo file Access e quindi necessito dei drivers ODBC.Ho seguito questa guida http://doc.qt.io/qt-5/sql-driver.html ed ho installato i drivers unixODBC (il comando odbc_config --version mi ritorna 2.3.4) e poi sono andato per compilare il tutto con il qmake.
Mi sono messo quindi nella directory ~/Qt/5.9.1/Src/qtbase/src/plugins/sqldrivers/odbc ed ho lanciato il comando
sudo '/home/rusty/Qt/5.9.1/gcc_64/bin/qmake' "INCLUDEPATH+=/usr/local/include" "LIBS+=-L/usr/local/lib -lodbc" odbc.pro
Il comando mi ha ritornato questo errore
Project ERROR: Library 'odbc' is not defined.
Non so che cosa sbaglio.. Ho guardato diverse guide ma i passaggi sembrano questi.. Qualche hint?
PS la connection open nel software la faccio così:
bool connectionOpen(){ QSqlDatabase db = QSqlDatabase::database("Contact"); if (db.isOpen()) { return true; }else{ static QString path = PATH; path = QDir::toNativeSeparators(path); mydb = QSqlDatabase::addDatabase("QODBC", "Contact"); QString params="Driver={Microsoft Access Driver (*.mdb)};FIL={Access};DBQ="+ path; mydb.setDatabaseName(params); if (!mydb.open()) { qDebug() << "Error: connection with database fail"; qDebug() << mydb.lastError().text(); return false; } else { qDebug() << "Database: connection ok"; return true; } return true; } }
E l'app mi da questo errore
QSqlDatabase: QODBC driver not loaded QSqlDatabase: available drivers: QSQLITE QMYSQL QMYSQL3 QPSQL QPSQL7 Error: connection with database fail "Driver not loaded Driver not loaded"
-
Hi, don't speak Italian but nevertheless I think you've been bitten by this bug
The workaround is to edit the .pro file: ~/Qt/5.9.1/Src/qtbase/src/plugins/sqldrivers/odbc/odbc.pro:
TARGET = qsqlodbc HEADERS += $$PWD/qsql_odbc_p.h SOURCES += $$PWD/qsql_odbc.cpp $$PWD/main.cpp # QMAKE_USE += odbc ### comment out this line unix: DEFINES += UNICODE OTHER_FILES += odbc.json PLUGIN_CLASS_NAME = QODBCDriverPlugin include(../qsqldriverbase.pri)
and try this command:
sudo '/home/rusty/Qt/5.9.1/gcc_64/bin/qmake' "INCLUDEPATH+=/usr/local/include" "LIBS+=-L/usr/local/lib -lodbc"
Note: no odbc.pro at the end of the command.
-
@hskoglund you have been very kind to answer a question that you cannot fully understand.
I followed the steps you told me and i got no error this time. :)Anyway my application is still having problem while i try to connect to the DB.
The error is still the same :QSqlDatabase: QODBC driver not loaded QSqlDatabase: available drivers: QSQLITE QMYSQL QMYSQL3 QPSQL QPSQL7 Error: connection with database fail "Driver not loaded Driver not loaded"
Do you think there are some passages i have skipped? Thank you for your time
!This is the error i got after make is launched
rm -f libqsqlodbc.so g++ -Wl,--no-undefined -Wl,-O1 -Wl,--enable-new-dtags -Wl,-z,origin -Wl,-rpath,\$ORIGIN/../../lib -Wl,-rpath,\$ORIGIN/../../lib -shared -o libqsqlodbc.so .obj/qsql_odbc.o .obj/main.o .obj/moc_qsql_odbc_p.o -L/usr/local/lib -lodbc -L/home/rusty/Qt/5.9.1/Src/qtbase/lib -lQt5Sql -lQt5Core -lpthread /usr/bin/ld: saltato /home/rusty/Qt/5.9.1/Src/qtbase/lib/libQt5Sql.so incompatibile durante la ricerca di -lQt5Sql /usr/bin/ld: impossibile trovare -lQt5Sql /usr/bin/ld: saltato /home/rusty/Qt/5.9.1/Src/qtbase/lib/libQt5Core.so incompatibile durante la ricerca di -lQt5Core /usr/bin/ld: impossibile trovare -lQt5Core collect2: error: ld returned 1 exit status Makefile:73: set di istruzioni per l'obiettivo "/home/rusty/Qt/5.9.1/Src/qtbase/plugins/sqldrivers/libqsqlodbc.so" non riuscito make: *** [/home/rusty/Qt/5.9.1/Src/qtbase/plugins/sqldrivers/libqsqlodbc.so] Errore 1
-
Hi, it looks almost ok except for
.... -L/home/rusty/Qt/5.9.1/Src/qtbase/lib...
on the g++ command line. That's why ld cannot find libQt5Sql.so etc.
For it to work, it should be...-L/home/rusty/Qt/5.9.1/gcc_64/lib...
Perhaps the qmake command took a wrong turn somewhere :-)
Anyway, what you can do, is edit the Makefile that qmake created, it should be in your odbc directory, look for the line starting with LIBS, it should look like this:LIBS = $(SUBLIBS) -L/usr/local/lib -lodbc -L/home/rusty/Qt/5.9.1/gcc_64/lib -lQt5Sql -lQt5Core -lpthread
If if does not, try changing it. Then touch a .cpp file, .e.g.
touch qsql_odbc.cpp
and try make again. -
@hskoglund you were right, i make the modification you told me to do and now i have my ODBC3 driver installed. Now i have some problem while connecting with the DB but ,at least, is not a driver problem!
Thank you!