Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Cannot build MySQL plugin



  • Hello,
    I am a hobbyist programmer and a totally newcomer to Qt, but I have moderate experience in C ++ and other SDKs
    Since I want to focus on database application development for my personal needs, I tried to connect to a MySQL database. Soon I realized that I have to build, by myself, the MySQL plugin
    I followed various instructions reading relative threads from this forum and watched YouTube videos. I also read the official help files (https://doc.qt.io/qt-5/sql-driver.html) of this topic, but I didn't manage to build the plugin.
    I have installed the Qt 5.14.2 and the MySQL Connector to the following paths in my hard drive:
    "C:\Qt" and
    "C:\Program Files\MySQL\MySQL Connector C 6.1"
    I think there are two methods to build the plugin. The first method is to open the corresponding project (in my case the MySQL) from the following path:
    "C:\Qt\5.14.2\Src\qtbase\src\plugins\sqldrivers\mysql"
    I modified the project in order to include the needed header files and include the needed libraries as follows:
    Qt Creator image
    but the Qt creator says that "library mysql is not defined"
    The second method is the command line prompt using the qmake. The following image shows the same error:
    Command line image
    I don't know what I am doing wrong and I am stuck. Any help will be appreciated


  • Qt Champions 2017

    @george said in Cannot build MySQL plugin:

    Before I start, I am wondering if I have to modify the project file

    You shouldn't.

    I had added the following lines

    Don't do that, you provide the paths on the command line, as per the documentation. Don't forget to quote the paths, as they contain spaces.


  • Lifetime Qt Champion

    You did not set up your environment correct. When you use MSVC you have to open the correct visual studio command prompt. When using MinGW then it's not nmake but mingw32-make (as written in the documentation)



  • Thank you for your response.

    When you use MSVC you have to open the correct visual studio command prompt. 
    

    Is this the one shown in the screenshot?
    alt text


  • Lifetime Qt Champion

    Hi,

    If it's the one matching the Qt version used in your Kit then yes.



  • Hi SGaist,
    alt text
    I think it is, because I've installed only the MSVC 64bit compiler
    Therefore it is not the set up of my environment, the reason I cannot build the plugin...


  • Lifetime Qt Champion

    You should check the test logs generated to see what exactly failed when the detection ran.



  • Could you please point me out where I can find these test logs?


  • Lifetime Qt Champion

    In the folder where you call qmake.



  • In the folder where you call qmake.
    

    I call the qmake from the folder:
    C:\Qt\5.14.2\Src\qtbase\src\plugins\sqldrivers\mysql
    In the following image there is a list of all files. There is no log files there (all subfolders are empty)
    alt text

    http://www.mediafire.com/view/vgec6rp2ldmf9lh/qt%235.jpg/file


  • Qt Champions 2017

    Hi,
    Open the .pro file for the plugin and change the line which reads:

    QMAKE_USE += mysql
    

    to:

    # QMAKE_USE += mysql
    

    Then rerun qmake and build with make/nmake. Then you can see what the compiler complained about exactly. Do let us know, I had that problem compiling psql because I mixed the arch by accident.



  • Hi kshegunov,
    Although I don't know what the QMAKE_USE += mysql instruction does, I understand that the '#' symbol is for remarks
    I followed your instruction.
    From the command prompt, I am getting no messages, so I opened the project from the creator and there are no errors.
    The compiler output window among other displays something about "win32-msvc", but I've the 64bit version installed:

    20:06:46: Running steps for project mysql...
    20:06:46: Starting: "C:\Qt\5.14.2\msvc2017_64\bin\qmake.exe" C:\Qt\5.14.2\Src\qtbase\src\plugins\sqldrivers\mysql\mysql.pro -spec win32-msvc "CONFIG+=debug" "CONFIG+=qml_debug"
    

    In the following image you can see the full compiler output
    alt text
    http://www.mediafire.com/view/vfi179q0efuqh5t/qt%236.jpg/file
    But if everything is OK, where is the plugin? I searched for a ".dll" file in the subfolders but all they are empty


  • Lifetime Qt Champion

    You did not follow the documentation - you have to run qmake in the sqldrivers subdir...


  • Qt Champions 2017

    @george said in Cannot build MySQL plugin:

    From the command prompt, I am getting no messages, so I opened the project from the creator and there are no errors.

    You didn't invoke the generated makefile as far as I could see from your screenshot. So I wouldn't expect you to see any messages. ;) After you run the qmake, you do need to call nmake to start things rolling.

    @Christian-Ehrlicher said in Cannot build MySQL plugin:

    You did not follow the documentation - you have to run qmake in the sqldrivers subdir...

    True, but don't lose patience on us. He just tried to follow what I asked, have some faith. ;)



  • First of all, I would like to thank you for spending your valuable time, reading my posts and try to guide me.
    It is true that I went a step forward. First I ran the vcvarsall.bat (I did not execute this batch file before). I suppose that sets some environment variables, right?
    From the command prompt and in the following directory: "C:/Qt/15.4.2/Src/qtbase/src/sqldrivers" I build the plugin as follows:

    qmake -- MYSQL_INCDIR="C:/Program Files/MySQL/MySQL Connector C 6.1/include" MYSQL_LIBDIR="C:/Program Files/MySQL/MySQL Connector C 6.1/lib"
    

    Here is the output:
    alt text
    http://www.mediafire.com/view/swazfssbaa0dg2u/qt%237.jpg/file
    But what is the next step?
    If I enter:

    nmake sub-mysql
    

    as manual says, I am getting the following errors:

    Microsoft (R) Program Maintenance Utility Version 14.16.27035.0
    Copyright (C) Microsoft Corporation.  All rights reserved.
    
            cd mysql\ && ( if not exist Makefile C:\Qt\5.14.2\msvc2017_64\bin\qmake.exe -o Makefile C:\Qt\5.14.2\Src\qtbase\src\plugins\sqldrivers\mysql\mysql.pro ) && "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\bin\HostX64\x64\nmake.exe" -f Makefile
    
    Microsoft (R) Program Maintenance Utility Version 14.16.27035.0
    Copyright (C) Microsoft Corporation.  All rights reserved.
    
            "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\bin\HostX64\x64\nmake.exe" -f Makefile.Release all
    
    Microsoft (R) Program Maintenance Utility Version 14.16.27035.0
    Copyright (C) Microsoft Corporation.  All rights reserved.
    
            link /NOLOGO /DYNAMICBASE /NXCOMPAT /DEBUG /OPT:REF /INCREMENTAL:NO /DLL /SUBSYSTEM:WINDOWS /VERSION:5.14 /OUT:..\plugins\sqldrivers\qsqlmysql.dll @C:\Users\George\AppData\Local\Temp\nmEA57.tmp
    LINK : fatal error LNK1181: cannot open input file 'lmysql.obj'
    NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\bin\HostX64\x64\link.EXE"' : return code '0x49d'
    Stop.
    NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\bin\HostX64\x64\nmake.exe"' : return code '0x2'
    Stop.
    NMAKE : fatal error U1077: 'cd' : return code '0x2'
    Stop.
    

  • Qt Champions 2017

    @george said in Cannot build MySQL plugin:

    LINK : fatal error LNK1181: cannot open input file 'lmysql.obj'

    Do you by any chance use a statically built Qt? This linker error is rather odd.



  • @kshegunov said in Cannot build MySQL plugin:

    Do you by any chance use a statically built Qt?

    Hmm... How can I check this?
    I searched my entire hard drive for the file "lmysql.obj", but I found nothing


  • Lifetime Qt Champion

    Please make sure that there are no leftovers in the sqldrivers subdir (best is to remove this subdir and unpack it again) and try again.


  • Qt Champions 2017

    @george said in Cannot build MySQL plugin:

    I searched my entire hard drive for the file "lmysql.obj", but I found nothing

    Hence I was suspicious. How did you obtain the sources, did you clone them from git or unpacked them from an archive, or maybe installed them through the maintenance tool? Christian's advice is a good one at this point, you want to make sure there are no leftovers because that can break the build.



  • I'll uninstall the Qt entirely and I'll delete the Qt folder.
    Then, I'll install from scratch the SDK using the online installer (only the MSVC 64 bit compiler)
    Then I'll let you know since the installation will take some time.


  • Qt Champions 2017

    Sounds like a plan.

    @george said in Cannot build MySQL plugin:

    Then, I'll install from scratch the SDK using the online installer (only the MSVC 64 bit compiler)

    One one note here, make sure that the SDK architecture (and compiler) you select matches the one of your command prompt that you're going to use. I had experienced this cryptic error when I tried to compile the PSQL driver with a 64 bit msvc, while my Qt distro was for 32 bit msvc. I know it sounds silly but it's an easy error to make, and not very obvious if you actually make it.



  • @kshegunov said in Cannot build MySQL plugin:

    make sure that the SDK architecture (and compiler) you select matches the one of your command prompt that you're going to use

    I noticed that the installer, creates only those command prompts shortcuts in the windows start menu that they correspond to the compiler versions chosen during the installation.
    I choose only one compiler to avoid such errors. When I will get better knowledge of how Qt works then, I'll proceed with other compilers too



  • Now I have a fresh installation of Qt in my hard drive
    Before I start, I am wondering if I have to modify the project file

    mysql.pro
    

    in the following folder:

    C:\Qt\5.14.2\Src\qtbase\src\plugins\sqldrivers\mysql
    

    as I did in my first post. I had added the following lines:

    INCLUEPATH += C:/Program Files/MySQL/MySQL Connector C 6.1/include
    QMAKE_LIBDIR += C:/Program Files/MySQL/MySQL Connector C 6.1/lib
    LIBS += -lmysql
    

  • Qt Champions 2017

    @george said in Cannot build MySQL plugin:

    Before I start, I am wondering if I have to modify the project file

    You shouldn't.

    I had added the following lines

    Don't do that, you provide the paths on the command line, as per the documentation. Don't forget to quote the paths, as they contain spaces.



  • Well, I managed to connect with my database, thanks to all the people they responded to my posts, and especially to you kshegunov
    alt text

    The most important reason that I've never used the QT, it is I never manage to connect with a remote database. Now I can use and learn this SDK which I believe it is the most comprehensive SDK around C++, targeting to database applications for my personal needs

    For people like me who does not have good knowledge around Qt I will post the steps I followed:

    1. Make a fresh install of Qt BUT only one compiler (if you do not know what are you doing!). I choosed the MSVC 2017 64bit. I installed the QT in C:\Qt
      alt text
      alt text

    2. Install the MySQL Connector . I installed in C:\Program Files\MySQL\MySQL Connector 6.1

    3. Click on the Windows start menu the shortcut for the command prompt of MSVC 2017 64-bit
      alt text

    4. Find in your hard drive the file vcvarsall.bat and execute it (you sould have Microsoft Visual Studio 2017 installed on your hard drive)
      alt text

    5. Go to the C:\Qt\5.14.2\Src\qtbase\src\plugins\sqldrivers and execute the following command (according to Qt manual)

    qmake -- MYSQL_INCDIR="C:/Program Files/MySQL/MySQL Connector C 6.1/include" MYSQL_LIBDIR="C:/Program Files/MySQL/MySQL Connector C 6.1/lib"
    

    and then

    nmake
    

    and then

    nmake install
    

    You'll see a lot of output. If everything is OK you should see the following files:
    qsqlmysql.dll and qsqlmysqld.dll
    in the folder C:\Qt\5.14.2\msvc2017_64\plugins\sqldrivers (see the first image of this post)


Log in to reply