如何使用MinGW在Windows上构建Qt QOCI(Oracle数据库驱动程序)? [英] How to build Qt QOCI (Oracle Database driver) on Windows with MinGW?

查看:132
本文介绍了如何使用MinGW在Windows上构建Qt QOCI(Oracle数据库驱动程序)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这最后两天,我花了很多时间尝试为Qt调试和发布Oracle数据库驱动程序,但均未成功. Qt Project中提供的手册( Oracle调用接口(OCI)驱动程序问题

  • 在制作Oci Driver时找不到头文件Qt
  • 由于两个来源都不完整,并且没有确切地讲授如何创建dll,因此我将在此处回答此问题来写该方法.

    仍然存在的唯一疑问是:是否有更好的方法来做到这一点?我的意思是,我想上面提到的Qt Project网站中介绍的编译这些库的标准方法应该可以在没有我(和其他人)必须做的所有手动工作的情况下工作.那么我/我的Qt/其他地方是否有问题,或者Qt Project的手册不完整,仅此而已?

    解决方案

    这是方法:

    初步注意事项:

    我安装了QtSDK/QtCreator/Qt 4.8.1 32 lib,因此我在目录系统中同时安装了QtSources文件夹以及用于桌面的Qt 4.8.1(MinGW)"-命令提示符准备与Qt一起使用. A还安装了Oracle数据库32,并在其中包含文件夹"C:\ Oracle \"和"include"和"lib"文件夹.在"include"中有.h(例如oci.h),在"lib"中有.dlls和.lib(例如oci.dll),所有这些都是编译所需的.在Qt Project文档之后,我将"c:\ oracle \ bin"添加到PATH环境变量中(计算机属性->高级系统设置->选项卡高级"->环境变量->系统变量部分).

    第一次尝试:

    在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
    

    %QTDIR%表示Qt源代码所在的文件夹.就我而言,这是:"C:\ QtSDK \ QtSources \ 4.8.1 \".提示:将此代码放在批处理文件(name.bat)中.

    遇到的第一个问题是报告某些文件丢失:oci.h和qsqlcachedresult_p.h.第一个是某种问题的结果,而mingw试图遇到上面的include文件夹,而第二个可能是Qt错误:带有相应文件夹的qsqlcachedresult_p.h实际上丢失了.

    第二个问题是通过将文件从其实际位置复制并粘贴到所需的缺少路径中而解决的.它位于"C:\ QtSDK \ QtSources \ 4.8.1 \ src \ sql \ kernel"中,应复制到"C:\ QtSDK \ Desktop \ Qt \ 4.8.1 \ mingw \ include \ QtSql \ private"( 私人"文件夹需要创建).

    根据同一来源,应该通过将Oracle包含路径放在%QTDIR%\ src \ plugins \ sqldrivers \ oci中的makefile.release和makefile.debug文件的INCPATH变量中来纠正第一个问题:

    在调试中:

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

    发布中

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

    (我也将lib路径用于保证)

    手动调整这两个文件的问题是,下次您键入"qmake oci.pro"时,将重新创建两个文件,并且丢失调整内容.因此,现在您应该再次键入Qt Project的代码,但不要输入"qmake oci.pro"这一行.

    第二次尝试:

    完成此操作后,前两个问题已解决,但ld.exe报告找不到-loci(oci.dll文件).为了纠正这个问题,我将oci lib路径放在LIBS变量中:

    在调试中:

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

    要发布.

    第三次尝试:

    完成此操作后,键入Qt Project的代码(不带"qmake oci.pro")即可正常运行.唯一的问题是仅创建了调试库.因此,要纠正此问题,我必须在以下公式中重复上述一些步骤:

    1. 键入原始Qt项目代码,并将qmake行更改为"qmake oci.pro"CONFIG + = release".
    2. 像以前一样,在%QTDIR%\ src \ plugins \ sqldrivers \ oci中编辑makefile.release文件.
    3. 再次键入Qt Project代码,现在没有qmake行.

    现在,用于释放模式的dll和.a文件也应该在%QTDIR%\ src \ plugins \ sqldrivers \ oci中的相应文件夹中遇到.

    完成:

    最后,将文件libqsqloci4.a,qsqloci4.dll(发行版),libqsqlocid4.a,qsqlocid4.dll(调试)复制到C:\ QtSDK \ Desktop \ Qt \ 4.8.1 \ mingw \ plugins \ sqldrivers文件夹中MinGW所在的sql dll可以在其中使用,并且您应该能够在Qt中使用OCI驱动程序没有问题.要进行测试,请转到Qt Creator,然后输入以下或类似的代码:

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

    教程结束.

    得出的结论:第

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

    原始Qt Project代码中的

    可能无济于事.此外,键入原始代码将仅编译调试OCI库.

    我希望它将对您有帮助!

    Momergil

    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

    这篇关于如何使用MinGW在Windows上构建Qt QOCI(Oracle数据库驱动程序)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆