Using system ODBC library with Qt
-
wrote on 24 Nov 2023, 03:57 last edited by
Hello,
I have a large software package that uses ODBC version 3.5 calls to query a mysql database server. The database does not use the Qt database framework--it uses just the bare ODBC function calls. The software was developed on linux in the eclipse IDE and it works fine. The ODBC function calls require the system ODBC library libodbc.I have been trying to get this ODBC code base to work in a Qt environment. When I include the system odbc library in the Qt .pro file, the software complies without error but I end up having strange run-time errors.
The .pro file has this line to add the odbc library while building the application.
...
LIBS += -L/usr/lib64 -lodbc
...Using Qt 6.6 I get the following errors when starting the application:
/home/glaird/workspaceQt/BO_DB_Write_Exec/BO_DB_Write_Exec: /usr/lib64/libQt6Core.so.6: versionQt_6.6' not found (required by /home/glaird/workspaceQt/BO_DB_Write_Exec/BO_DB_Write_Exec) /home/glaird/workspaceQt/BO_DB_Write_Exec/BO_DB_Write_Exec: /usr/lib64/libQt6Core.so.6: version
Qt_6.2.2_PRIVATE_API' not found (required by /usr/lib64/libQt6Gui.so.6)
/home/glaird/workspaceQt/BO_DB_Write_Exec/BO_DB_Write_Exec: /usr/lib64/libQt6Core.so.6: version `Qt_6.2.2_PRIVATE_API' not found (required by /usr/lib64/libQt6DBus.so.6)If I try Qt 5.15 I get this error at runtime:
/home/glaird/workspaceQt/BO_DB_Write_Exec/BO_DB_Write_Exec: symbol lookup error: /home/glaird/workspaceQt/BO_DB_Write_Exec/BO_DB_Write_Exec: undefined symbol: _ZdlPvm, version Qt_5I find that if I add the libobdc library to any Qt application I get these same sort of strange errors.
It looks to me like I have some symbol collisions between the Qt libraries and the odbc library. I am not sure what to do?
Anyone have suggestions. Thanks!
-
Hello,
I have a large software package that uses ODBC version 3.5 calls to query a mysql database server. The database does not use the Qt database framework--it uses just the bare ODBC function calls. The software was developed on linux in the eclipse IDE and it works fine. The ODBC function calls require the system ODBC library libodbc.I have been trying to get this ODBC code base to work in a Qt environment. When I include the system odbc library in the Qt .pro file, the software complies without error but I end up having strange run-time errors.
The .pro file has this line to add the odbc library while building the application.
...
LIBS += -L/usr/lib64 -lodbc
...Using Qt 6.6 I get the following errors when starting the application:
/home/glaird/workspaceQt/BO_DB_Write_Exec/BO_DB_Write_Exec: /usr/lib64/libQt6Core.so.6: versionQt_6.6' not found (required by /home/glaird/workspaceQt/BO_DB_Write_Exec/BO_DB_Write_Exec) /home/glaird/workspaceQt/BO_DB_Write_Exec/BO_DB_Write_Exec: /usr/lib64/libQt6Core.so.6: version
Qt_6.2.2_PRIVATE_API' not found (required by /usr/lib64/libQt6Gui.so.6)
/home/glaird/workspaceQt/BO_DB_Write_Exec/BO_DB_Write_Exec: /usr/lib64/libQt6Core.so.6: version `Qt_6.2.2_PRIVATE_API' not found (required by /usr/lib64/libQt6DBus.so.6)If I try Qt 5.15 I get this error at runtime:
/home/glaird/workspaceQt/BO_DB_Write_Exec/BO_DB_Write_Exec: symbol lookup error: /home/glaird/workspaceQt/BO_DB_Write_Exec/BO_DB_Write_Exec: undefined symbol: _ZdlPvm, version Qt_5I find that if I add the libobdc library to any Qt application I get these same sort of strange errors.
It looks to me like I have some symbol collisions between the Qt libraries and the odbc library. I am not sure what to do?
Anyone have suggestions. Thanks!
@gdlaird said in Using system ODBC library with Qt:
I find that if I add the libobdc library to any Qt application I get these same sort of strange errors
Do you mean you can build Qt application if you do not add libodbc?
How did you install Qt? You seem to have Qt installed in /usr/lib64.
-
@gdlaird said in Using system ODBC library with Qt:
I find that if I add the libobdc library to any Qt application I get these same sort of strange errors
Do you mean you can build Qt application if you do not add libodbc?
How did you install Qt? You seem to have Qt installed in /usr/lib64.
wrote on 24 Nov 2023, 15:44 last edited by@jsulm What I meant was that I could take a non-ODBC Qt application and add the "LIBS += -L/usr/lib64 -lodbc" line to the .pro file, I will then get these strange run-time errors. I did this to see what would happen as a test--I would think that if an application ODBC calls, adding the library shouldn't make any difference--but it does.
Qt 5.15 is installed in /usr/local/Qt and Qt 6.3,6.6 are installed in /usr/local/Qt6.
I have many other Qt applications and they work fine with both Qt 5 & 6. I have tried to take as many Qt system elements out of the faulty application. There are no QObject, QThread, etc. I am using boost for threading and asio for socket communication.
The problem seems to be somewhat intermittent; with Qt 5 I can run debug and single step into the program using gdb a ways and then it will crash when I try to delete (correctly) an object that had been allocated. Other times, I can't even get the application to start without the error. So, there is some sort of interaction between Qt libraries and libodbc.
To be clear, I cannot get the application to compile and link without the odbc library.
Here is the .pro file I am using:
CONFIG += c++17
CONFIG -= app_bundleQMAKE_CXX = g++-9
QMAKE_CXXFLAGS += -std=c++0x -pthreadYou can make your code fail to compile if it uses deprecated APIs.
In order to do so, uncomment the following line.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
SOURCES +=
../MS_ClassLib/sheet_defs.cpp
../MS_ClassLib/message_base.cpp
../MS_ClassLib/mesid_bo_db_write.cpp
main.cpp
DB_Rtns/BOD_DBRtns.cpp
DB_Rtns/BOD_DBTables.cpp
DB_Rtns/GameNormalize.cpp
DB_Rtns/ODBC_Database.cpp
DB_Rtns/ODBC_Objects.cpp
DB_Rtns/ODBC_Tables.cpp
DB_Rtns/dbproc.cpp
socketio.cppHEADERS +=
DB_Rtns/BOD_DBTables.h
DB_Rtns/GameNormalize.h
DB_Rtns/ODBC_Database.h
DB_Rtns/ODBC_Objects.h
DB_Rtns/ODBC_Tables.h
../MS_ClassLib/sheet_defs.h
../MS_ClassLib/MS_Defs.h
../MS_ClassLib/message_base.h
../MS_ClassLib/mesid_bo_db_write.h
DB_Rtns/dbproc.hLD_LIBRARY_PATH=/usr/lib64
LIBS += -L/usr/local/lib -lboost_thread
LIBS += -L/usr/local/lib -lboost_chrono
LIBS += -L/usr/lib64 -lodbc
LIBS += -pthreadINCLUDEPATH += /usr/local/asio/include
INCLUDEPATH += /usr/local/boostDEPENDPATH += /usr/local/boost
DEPENDPATH += /usr/lib64
DEPENDPATH += /usr/local/boost/libDESTDIR = ../BO_DB_Write_Exec
TARGET = BO_DB_Write_Exec -
@jsulm What I meant was that I could take a non-ODBC Qt application and add the "LIBS += -L/usr/lib64 -lodbc" line to the .pro file, I will then get these strange run-time errors. I did this to see what would happen as a test--I would think that if an application ODBC calls, adding the library shouldn't make any difference--but it does.
Qt 5.15 is installed in /usr/local/Qt and Qt 6.3,6.6 are installed in /usr/local/Qt6.
I have many other Qt applications and they work fine with both Qt 5 & 6. I have tried to take as many Qt system elements out of the faulty application. There are no QObject, QThread, etc. I am using boost for threading and asio for socket communication.
The problem seems to be somewhat intermittent; with Qt 5 I can run debug and single step into the program using gdb a ways and then it will crash when I try to delete (correctly) an object that had been allocated. Other times, I can't even get the application to start without the error. So, there is some sort of interaction between Qt libraries and libodbc.
To be clear, I cannot get the application to compile and link without the odbc library.
Here is the .pro file I am using:
CONFIG += c++17
CONFIG -= app_bundleQMAKE_CXX = g++-9
QMAKE_CXXFLAGS += -std=c++0x -pthreadYou can make your code fail to compile if it uses deprecated APIs.
In order to do so, uncomment the following line.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
SOURCES +=
../MS_ClassLib/sheet_defs.cpp
../MS_ClassLib/message_base.cpp
../MS_ClassLib/mesid_bo_db_write.cpp
main.cpp
DB_Rtns/BOD_DBRtns.cpp
DB_Rtns/BOD_DBTables.cpp
DB_Rtns/GameNormalize.cpp
DB_Rtns/ODBC_Database.cpp
DB_Rtns/ODBC_Objects.cpp
DB_Rtns/ODBC_Tables.cpp
DB_Rtns/dbproc.cpp
socketio.cppHEADERS +=
DB_Rtns/BOD_DBTables.h
DB_Rtns/GameNormalize.h
DB_Rtns/ODBC_Database.h
DB_Rtns/ODBC_Objects.h
DB_Rtns/ODBC_Tables.h
../MS_ClassLib/sheet_defs.h
../MS_ClassLib/MS_Defs.h
../MS_ClassLib/message_base.h
../MS_ClassLib/mesid_bo_db_write.h
DB_Rtns/dbproc.hLD_LIBRARY_PATH=/usr/lib64
LIBS += -L/usr/local/lib -lboost_thread
LIBS += -L/usr/local/lib -lboost_chrono
LIBS += -L/usr/lib64 -lodbc
LIBS += -pthreadINCLUDEPATH += /usr/local/asio/include
INCLUDEPATH += /usr/local/boostDEPENDPATH += /usr/local/boost
DEPENDPATH += /usr/lib64
DEPENDPATH += /usr/local/boost/libDESTDIR = ../BO_DB_Write_Exec
TARGET = BO_DB_Write_Exec -
@gdlaird "-I would think that if an application ODBC calls" should be
"-I would think that if an application has no ODBC calls"It looks like you're mixing different Qt versions. I would guess you have a system Qt installation in /usr/lib64 and a custom one (e.g. installed via the Qt online installer) somewhere else. Now the problem is that when you execute your application, also the Qt libs from /usr/lib64 are used which have the wrong version.
You have two options
- move the odbc lib to another location (e.g. create symlink in /usr/local/lib64 and link against them there
- use the sytem-wide Qt installation instead the one from the Qt online installer
No Qt specific problem but one you get as soon as you have a library with more than one version on your system. I would give the first option a try.
-
It looks like you're mixing different Qt versions. I would guess you have a system Qt installation in /usr/lib64 and a custom one (e.g. installed via the Qt online installer) somewhere else. Now the problem is that when you execute your application, also the Qt libs from /usr/lib64 are used which have the wrong version.
You have two options
- move the odbc lib to another location (e.g. create symlink in /usr/local/lib64 and link against them there
- use the sytem-wide Qt installation instead the one from the Qt online installer
No Qt specific problem but one you get as soon as you have a library with more than one version on your system. I would give the first option a try.
wrote on 24 Nov 2023, 21:46 last edited by@Christian-Ehrlicher That was exactly the problem. Thank you so much!
-
1/6