简体   繁体   English

如何使用MinGW在Windows上构建Qt QOCI(Oracle数据库驱动程序)?

[英]How to build Qt QOCI (Oracle Database driver) on Windows with MinGW?

This last two days I spend trying to build both debug and release Oracle database drivers for Qt without success. 在过去的两天里,我花了很多时间尝试为Qt构建调试和发布Oracle数据库驱动程序。 The manual that is given in Qt Project ( link ) is far incomplete and in reality things are much more complicated than what is shown. Qt Project( 链接 )中给出的手册很不完整,实际上事情比显示的要复杂得多。

After much trying, I finally managed to build the dlls with the help of some also incomplete posts on the web: 经过多次尝试,我终于在网上一些不完整的帖子的帮助下设法建立了dll:

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. 由于两个来源都不完整,并且没有准确地教导如何创建dll,我将通过回答这个问题来写这个方法。

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. 我的意思是,我认为编译这些库的标准方法,如上面引用的Qt项目网站所示,应该没有我(和其他人)必须做的所有手册内容。 So was there something wrong about me/my Qt/anything else or Qt Project's manual is incomplete and that's that? 那么我/我的Qt /其他任何东西都有问题或者Qt Project的手册是不完整的那就是那个?

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. 我安装了QtSDK / QtCreator / Qt 4.8.1 32 lib,所以我的目录系统中有两个QtSources文件夹以及“Qt 4.8.1 for Desktop(MinGW)” - 准备用于Qt的命令提示符。 A also had Oracle database 32 installed with the folder C:\\Oracle\\ with "include" and "lib" folders inside. A还安装了Oracle数据库32,文件夹为C:\\ Oracle \\,里面有“include”和“lib”文件夹。 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. 在“include”中有.h,例如oci.h,在“lib”中有.dlls和.lib,例如oci.dll,所有这些都是编译所必需的。 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). 在Qt项目文档之后,我将“c:\\ oracle \\ bin”添加到PATH环境变量(计算机属性 - >高级系统设置 - >选项卡“高级” - >环境变量 - >系统变量部分)。

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: Qt Project网站中显示的针对MinGW调整的编译的默认代码(实际上是调试库的一个)如下:

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. %QTDIR%表示Qt源代码所在的文件夹。 In my case this is: "C:\\QtSDK\\QtSources\\4.8.1\\". 在我的例子中,这是:“C:\\ QtSDK \\ QtSources \\ 4.8.1 \\”。 Tip: put this code in a batch file (name.bat). 提示:将此代码放在批处理文件(name.bat)中。

The first problem encountered was that some files were reported missing: oci.h and qsqlcachedresult_p.h. 遇到的第一个问题是报告丢失了一些文件:oci.h和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. 第一个是某种问题的结果,而mingw试图遇到上面的include文件夹,而第二个可能是Qt错误:qsqlcachedresult_p.h与它的相应文件夹实际上是丢失的。

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). 它位于“C:\\ QtSDK \\ QtSources \\ 4.8.1 \\ src \\ sql \\ kernel”中,应复制到“C:\\ QtSDK \\ Desktop \\ Qt \\ 4.8.1 \\ mingw \\ include \\ QtSql \\ private”(需要创建“私有”文件夹)。

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: 根据相同的来源,第一个问题应该通过在%QTDIR%\\ src \\ plugins \\ sqldrivers \\ oci中的makefile.release和makefile.debug文件中的INCPATH变量中放置Oracle include路径来纠正:

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). (我也把lib路径用于保证)。

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. 手动调整这两个文件的问题是,下次键入“qmake oci.pro”时,将重新创建这两个文件并丢失调整。 So now you should type Qt Project's code again but without that "qmake oci.pro" line. 所以现在你应该再次键入Qt Project的代码,但没有“qmake oci.pro”行。

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). 完成后,前两个问题得到解决,但是ld.exe报告找不到-loci(oci.dll文件)。 In order to correct this, I put the oci lib path in the LIBS variable: 为了纠正这个问题,我将oci lib路径放在LIBS变量中:

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. 完成后,键入Qt Project的代码(没有“qmake oci.pro”)运行正常。 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" ". 键入原始Qt项目代码,并将qmake行更改为“qmake oci.pro”CONFIG + = release“”。
  2. Edit the makefile.release file in %QTDIR%\\src\\plugins\\sqldrivers\\oci as done before. 编辑%QTDIR%\\ src \\ plugins \\ sqldrivers \\ oci中的makefile.release文件,如前所述。
  3. Type again the Qt Project code, now without the qmake line. 再次输入Qt Project代码,现在没有qmake行。

And now the dll and .a files for release mode should also be encountered in its respective folder inside %QTDIR%\\src\\plugins\\sqldrivers\\oci. 现在,在%QTDIR%\\ src \\ plugins \\ sqldrivers \\ oci中的相应文件夹中也应该遇到发布模式的dll和.a文件。

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. 最后,将文件libqsqloci4.a,qsqloci4.dll(release),libqsqlocid4.a,qsqlocid4.dll(debug)复制到C:\\ QtSDK \\ Desktop \\ Qt \\ 4.8.1 \\ mingw \\ plugins \\ sqldrivers,sql dlls所在的文件夹位于MinGW与他们合作,你应该能够在Qt中使用OCI驱动程序没问题。 To test, go to Qt Creator and type the following or similar code: 要进行测试,请转到Qt Creator并键入以下或类似代码:

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. 在原来的Qt项目代码中可能没有任何帮助。 Also typing the original code will only compile the debug OCI library. 键入原始代码也只能编译调试OCI库。

I hope it will help! 我希望它会有所帮助!

Momergil Momergil

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM