Вопрос

This last two days I spend trying to build both debug and release Oracle database drivers for Qt without success. The manual that is given in Qt Project (link) is far incomplete and in reality things are much more complicated than what is shown.

After much trying, I finally managed to build the dlls with the help of some also incomplete posts on the web:

Since both sources are incomplete and don't exactly teach how to create the dlls, I'll write here the method by answering this question.

The only doubt that still remains is: is there a better way of doing this? I mean, I suppose that the standard way of compiling these libraries, as presented in the Qt Project website referenced above, should work without all the manual stuff that I (and the others) had to do. So was there something wrong about me/my Qt/anything else or Qt Project's manual is incomplete and that's that?

Это было полезно?

Решение

So this is how to do it:

Preliminar notes:

I had QtSDK/QtCreator/Qt 4.8.1 32 lib installed, so I had both QtSources folder in my directory system as well as "Qt 4.8.1 for Desktop (MinGW)" - the command prompt prepared for usage with Qt. A also had Oracle database 32 installed with the folder C:\Oracle\ with "include" and "lib" folders inside. In "include" there are the .h such as oci.h and in "lib" there are the .dlls and .lib such as oci.dll, all of them required for the compilation. Following the Qt Project documentation, I add "c:\oracle\bin" to the PATH environment variable (Computer properties -> Advanced system settings -> Tab "Advance" -> Environment Variables -> System variables section).

First try:

The default code (actually one for debug lib) for the compilation as shown in Qt Project website, adjusted for MinGW, is as following:

set INCLUDE=%INCLUDE%;c:\oracle\oci\include
set LIB=%LIB%;c:\oracle\oci\lib\msvc
cd %QTDIR%\src\plugins\sqldrivers\oci
qmake oci.pro
mingw32-make

By %QTDIR% one means the folder where Qt source codes are located. In my case this is: "C:\QtSDK\QtSources\4.8.1\". Tip: put this code in a batch file (name.bat).

The first problem encountered was that some files were reported missing: oci.h and qsqlcachedresult_p.h. The first is a result of some kind of problem while mingw tries to encounter the include folder above, while the second is probably a Qt mistake: the qsqlcachedresult_p.h with it's respective folder is actually missing.

The second problem was solved by copying and pasting the file from its actual place to the required, missing path. It is located in "C:\QtSDK\QtSources\4.8.1\src\sql\kernel" and should be copied to "C:\QtSDK\Desktop\Qt\4.8.1\mingw\include\QtSql\private" (the "private" folder need to be created).

According to the same source, the first problem should be corrected by placing the Oracle include path in the INCPATH variable in both makefile.release and makefile.debug files in %QTDIR%\src\plugins\sqldrivers\oci:

In Debug:

INCPATH       = -I"c:\QtSDK\Desktop\Qt\4.8.1\mingw\include\QtCore" (...) -I"c:\Oracle\include" -I"c:\Oracle\lib\msvc"  

In Release

INCPATH       = -I"c:\QtSDK\Desktop\Qt\4.8.1\mingw\include\QtCore" (...) -I"c:\Oracle\include" -I"c:\Oracle\lib\msvc" 

(I also put the lib path just for assurance).

The problem with manually adjusting those two files is that the next time you type "qmake oci.pro", both of them will be recreated and the adjustments, lost. So now you should type Qt Project's code again but without that "qmake oci.pro" line.

Second try:

When this was done, the first two problems were solved, but than ld.exe reported that couldn't find -loci (the oci.dll file). In order to correct this, I put the oci lib path in the LIBS variable:

In Debug:

LIBS        =        -L"c:\QtSDK\Desktop\Qt\4.8.1\mingw\lib" debug\qsqlocid_resource_res.o -loci -lQtSqld4 -lQtCored4  -L"c:\Oracle\lib\msvc"

Same for release.

Third try:

With this done, typing Qt Project's code (without "qmake oci.pro") run fine. The only problem is that only the debug libraries were created. So to correct this, I had to repeat some of the steps above in the following formula:

  1. Type the original Qt Project code with the qmake line changed to " qmake oci.pro "CONFIG+=release" ".
  2. Edit the makefile.release file in %QTDIR%\src\plugins\sqldrivers\oci as done before.
  3. Type again the Qt Project code, now without the qmake line.

And now the dll and .a files for release mode should also be encountered in its respective folder inside %QTDIR%\src\plugins\sqldrivers\oci.

Finishing:

Finally, copy files libqsqloci4.a, qsqloci4.dll (release), libqsqlocid4.a, qsqlocid4.dll (debug) to C:\QtSDK\Desktop\Qt\4.8.1\mingw\plugins\sqldrivers , the folder where sql dlls are located for MinGW to work with them, and you should be able to use OCI drivers in Qt no problem. To test, go to Qt Creator and type the following or similar code:

if (!QSqlDatabase::isDriverAvailable("QOCI"))
    cout << "FAILURE: No Oracle Database driver available." << endl;
else
    cout << "SUCCESS: Oracle Database driver found." << endl;

End of tutorial.

Conclusions taken: the lines

set INCLUDE=%INCLUDE%;c:\oracle\oci\include
set LIB=%LIB%;c:\oracle\oci\lib\msvc

in the original Qt Project code probably don't help in anything. Also typing the original code will only compile the debug OCI library.

I hope it will help!

Momergil

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top