PDA

View Full Version : Creating MySQL driver returns error



Momergil
19th January 2013, 15:47
Hello!

Some time ago I did a research in order to discover how to create the MySQL driver for Qt and after various failed helps I managed to find this website, whoose process to create such driver runs sucessfully:

[http://ieatbinary.com/2011/07/11/how-to-enable-mysql-support-in-qt-sdk-for-windows/]

After doing this process succesfully in two different machine, for the first time I'm incapable of creating the driver pointing always the error that mysql.h is missing:
8597

Could somebody please point out what is the problem? Where can I find mysql.h? Could this be due to the MySQL installation folder is in F: and Qt installation is in C:?

Thanks,

Momergil

Edit: at the end of the web page it is stated: "You can’t use MySQL 64 Bit (at the moment) to compile the plugin.". I'm not sure, but it is really probable that I'm using a 64 bit MySQL... Does somebody know if this restriction is still valid?

d_stranz
19th January 2013, 16:54
If the compiler is telling you it can't find mysql.h, it either means that you don't have developer API for MySQL installed (maybe you only have the actual run-time DBMS code), or you don't have the include path correctly specified in your makefile or .pro file.

Did you follow the instructions at the link you provided *exactly*?

It is irrelevant where your versions of Qt and MySQL are installed as long as you include the drive letter when you set up either the mysql environment variable or specify the include path.

Of course, it is entirely possible that you installed 64-bit MySQL by mistake, but that has nothing to do with the problem you are having. I think the comment on that web site probably means the author has a 32-bit Qt installation. You cannot mix 32-bit and 64-bit EXE and DLL Windows modules, even on a 64-bit machine.

Momergil
19th January 2013, 18:03
If the compiler is telling you it can't find mysql.h, it either means that you don't have developer API for MySQL installed (maybe you only have the actual run-time DBMS code), or you don't have the include path correctly specified in your makefile or .pro file.

Actually first I though that this was the problem: I didn't have the developer API, so today, thinking that that would fix the problem, I downloaded and installed this developer API.

8600

But the same problem as before appeared, as if nothign had changed.


Did you follow the instructions at the link you provided *exactly*?

Yep. The only difference is that MySQL is installed in the F: and not in C: as in the instructions.


It is irrelevant where your versions of Qt and MySQL are installed as long as you include the drive letter when you set up either the mysql environment variable or specify the include path.

Of course, it is entirely possible that you installed 64-bit MySQL by mistake, but that has nothing to do with the problem you are having. I think the comment on that web site probably means the author has a 32-bit Qt installation. You cannot mix 32-bit and 64-bit EXE and DLL Windows modules, even on a 64-bit machine.

Well, actually I think that my Qt is 32-bit version and MySQL is 64-bit :x

8601

I'll give a look a the .pro file, since I found the mysql.h in the MySQL directory; maybe that's the problem.

d_stranz
19th January 2013, 18:15
I am not sure about the comment regarding 64-bit MySQL. If you build your Qt MySQL plugin as 32-bit code, unless using that plugin requires you to load a 64-bit DLL from the MySQL distribution, then it should be OK. But I do not know how MySQL implements run-time access to the database server. If it is some kind of socket-based connection, then a 64-bit MySQL and a 32-bit Qt plugin shouldn't be a problem But if the connection is based on an interface through a 64-bit MySQL DLL, then it won't work.

If you build a 64-bit version of Qt, then you'll should be OK using a 64-bit MySQL. You just need to be sure that you have apples and apples everywhere, and not apples and oranges.

Momergil
19th January 2013, 18:22
Well, you were right about the .pro file: the include of mysql.h was not correct, so I redirected the link to MySQL folder in F: and the compilation went better, but a new problem arised:

8602

It seems that the compiler has some problem with empty sapaces in the name, and the manual sad to "use short path"... So following this instructions [http://superuser.com/questions/348079/how-can-i-find-the-short-path-of-a-windows-directory-file] I put PROGRA~1 where there was "Program Files" and MYSQLS~1.5 where there was MySQL Server 5.5. Once again the last problem was corrected, but a new one appeared after dozens of "undefined reference to", and this time I have no idea what to do:

8603

d_stranz
19th January 2013, 18:36
Well, now you have a link-time problem - that's what an "undefined reference" is - you (or the plugin you're trying to build) have used something declared in a header file, but you haven't told the linker where to find the object or library file that contains its implementation. Whatever you did to tell qmake where to find the header files, you also need to tell it where to find the MySQL .lib files to link to. And you will probably have to do the same trick with the Program Files directory name that you did to get include files to work.

Momergil
19th January 2013, 18:53
Well, now you have a link-time problem - that's what an "undefined reference" is - you (or the plugin you're trying to build) have used something declared in a header file, but you haven't told the linker where to find the object or library file that contains its implementation. Whatever you did to tell qmake where to find the header files, you also need to tell it where to find the MySQL .lib files to link to. And you will probably have to do the same trick with the Program Files directory name that you did to get include files to work.

Ouch... Well, I gave a look at qsql_mysql.cpp where the mingw was pointing this "undefined reference"s and followed thoose names (e.g. mysql_characterset_set_name) till reach mysql.h, where they are defined. So if I understood you correctly, what lacks is, so to speak, the mysql.cpp? Well I guess thoose implementations may be in libmysql.dll in "F:\Program Files\MySQL\MySQL Server 5.5\lib", what do you think? (you mentioned "you also need to tell it where to find the MySQL .lib files to link to" but I guess that was already told in the command line when I added "... "LIBS+=F:\PROGRA~1\MySQL\MYSQLS~1.5\lib\libmysql.li b")

In so being, how should I tell qmake to look for the implementations in this .dll?

d_stranz
19th January 2013, 19:17
You do not need to include any source code (.cpp) files from your MySQL installation. Don't go down that road.


"LIBS+=F:\PROGRA~1\MySQL\MYSQLS~1.5\lib\libmysql.l ib"

I do not use .pro files; I make Visual Studio projects out of everything, so I am not familiar with qmake syntax. But what you have there (assuming the extra space between "libmysql.l" and "ib" is just a cut-and-paste typo) looks OK to me.

If I were you though, I would start over and reinstall MySQL to a folder that doesn't have any spaces anywhere in the name. You don't have to install to "Program Files" and don't have to use the name "MySQL Server 5.5". You can install to "F:\MySQL_Server_5_5" and then you won't have to worry about mangling the names to make qmake happy and you can set the "mysql" environment variable and use %mysql% in qmake arguments instead of hard-coded paths.

Momergil
19th January 2013, 21:56
You do not need to include any source code (.cpp) files from your MySQL installation. Don't go down that road.

Yeah, I know, I just sad as for the argument ;)


But what you have there (assuming the extra space between "libmysql.l" and "ib" is just a cut-and-paste typo) looks OK to me.

yeah, I didn't noticed the space, but it was actually a mistake; you can see the printscreens that I don't put the spaces in the code.

But if it's OK, than I got a problem, because I already put that line of code in the process and with that line it didn't work :T


If I were you though, I would start over and reinstall MySQL to a folder that doesn't have any spaces anywhere in the name. You don't have to install to "Program Files" and don't have to use the name "MySQL Server 5.5". You can install to "F:\MySQL_Server_5_5" and then you won't have to worry about mangling the names to make qmake happy and you can set the "mysql" environment variable and use %mysql% in qmake arguments instead of hard-coded paths.

Well, while that can be done, I don't see actually good reasons for doing so. After all, the spaces problem is being solved using "short path", and the environment variable would be just a help, not anything that should make it work (actually you may re-read the instructional webpage and see that the guy there actually did use such environment variable). But once again, it doesn't seems to me that it would help with the actual problem - not to mension that would begin to crap my hard-disk's organization...

Momergil
28th February 2013, 03:16
Hello!

Just to give my feedback,

today I managed to install the mysql driver. The difference was that I follow one of the suggestions that were given to me: to uninstall current 64 mysql and install again the 32 mysql. After doing this, I managed to follow all the steps with no problem.


Thanks for the help!

Momergil