Pelles C forum

C language => Beginner questions => Topic started by: pjbrudal on October 12, 2017, 04:37:46 PM

Title: Using MySQL C Connector 6.1.11
Post by: pjbrudal on October 12, 2017, 04:37:46 PM
I try to access MySQL from Pelles C using Oracle's C connector version 6.1.11 (the most recent) with Pelles C IDE version 8.00, both in 32-bit version. But can't even compile and link a very trivial program. It's quite embarassing, since I used to be a professional C programmer from the mid-80's until around 2003 :( . I have attached the source files and the error messages and hope someone can tell me what's wrong. And yes, I have put the relevant path names into the boxes in Project Options -> Folders.
Title: Re: Using MySQL C Connector 6.1.11
Post by: Jokaste on October 12, 2017, 05:25:30 PM
try #include "crtdbg.h" rather than #include <crtdbg.h>
Title: Re: Using MySQL C Connector 6.1.11
Post by: frankie on October 12, 2017, 06:02:31 PM
Quote
Building Test.exe.
POLINK: error: Unresolved external symbol '_mysql_get_client_info@0'.
POLINK: fatal error: 1 unresolved external(s).
*** Error code: 1 ***
Done.
Have added the mysql connector library to the linker?
Have you used the C connector, not the C++ connector library?
Title: Re: Using MySQL C Connector 6.1.11
Post by: TimoVJL on October 12, 2017, 07:07:44 PM
missing libmysql.lib ?

Usually this in source helps to remember what libraries program needs.
Code: [Select]
#include <mysql.h>
#pragma comment(lib, "libmysql.lib")
Title: Re: Using MySQL C Connector 6.1.11
Post by: pjbrudal on October 13, 2017, 08:55:28 AM
Thanks a lot for the advice, which unfortunately didn't help in any way.
a) The file crtdbg.h is part of Microsoft Visual Studio, which I don't have. It is included from the file my_global.h, which is part of Oracle's MySQL C connector. Based on advice from another forum on the internet, I wrote a small crtdbg.h stub and put it in the connector's include folder. However, I just got other problems later in the compilation. So I dropped the my_global.h and used stdio.h, windows.h and winsock.h instead.
b) I have indeed added the include and lib folders to the Folder tag in Project Options, - and I know that C and C++ are different :-)
c) I have also got all the files that came with the MySQL connector.

Today changed the folder options to use the MariaDB C connector instead. This failed in a somewhat similar way as with Oracle's MySQL, as can be seen from the attachment. There are two problem areas:
Compiler: I get complaints about _stdcall used instead of _cdecl in some places in mysql.h. Do I need to include some other header files?
Linker: I get an error message that I guess has something to do with a 'decorated' function name. How can get the names to match?

I haven't used C for 15 years and I assume that things have changed over the years. And this is the first time I use Pelles C. I suspect there is something very simple that I've overlooked.
Title: Re: Using MySQL C Connector 6.1.11
Post by: TimoVJL on October 13, 2017, 10:03:13 AM
use pocc.exe option -Ze Enable Microsoft extensions
and check correct library libmysql.lib/libmariadb.lib is it for i386 ?
Title: Re: Using MySQL C Connector 6.1.11
Post by: pjbrudal on October 13, 2017, 01:12:41 PM
I have selected Enable Microsoft extensions in the compiler tag in project options. Shouldn't that be sufficient?
All my libraries are for X86 architecture, not for X64. And for Windows, not for Unix :-)

There are 2 separate problems: one with _stcall versus _cdecl and one with the library and the function names.

Have anyone else tried MySQL with Pelles C recently? I have read Jan Bodnar's tutorial, and used his examples, but it just won't work.
Title: Re: Using MySQL C Connector 6.1.11
Post by: TimoVJL on October 13, 2017, 03:48:09 PM
This example didn't gave any errors with that MySQL connector 6.1.11
Code: [Select]
#include <stdio.h>
//#include <mysql.h>
#include "mysql.h" // only for the depedencies for the zip
#pragma comment(lib, "libmysql.lib")
//#pragma comment(lib, "libmariadb.lib")
int _cdecl main(int argc, char *argv[])
{
printf("Testing testing testing\n");
printf("MySQL client version: %s\n", mysql_get_client_info());
// printf("MariaDB client version: %s\n", mysql_get_client_info());
return 0;
}

MariaDB have bugs in headers, varargs are not handled correctly.
Code: [Select]
Building TestMariaDB.obj.
C:\code\PellesC\MariaDB\include\mysql.h(444): warning #2203: Function 'mysql_load_plugin' can't be __stdcall, changed to __cdecl.
C:\code\PellesC\MariaDB\include\mysql.h(495): warning #2203: Function 'mariadb_get_infov' can't be __stdcall, changed to __cdecl.
C:\code\PellesC\MariaDB\include\mysql.h(572): warning #2203: Function 'mysql_optionsv' can't be __stdcall, changed to __cdecl.
C:\code\PellesC\MariaDB\include\mysql.h(573): warning #2203: Function 'mysql_get_optionv' can't be __stdcall, changed to __cdecl.
C:\code\PellesC\MariaDB\include\mysql.h(728): warning #2203: Function 'mariadb_get_infov' can't be __stdcall, changed to __cdecl.
C:\code\PellesC\MariaDB\include\mysql.h(782): warning #2203: Function 'mysql_optionsv' can't be __stdcall, changed to __cdecl.
C:\code\PellesC\MariaDB\include\mysql.h(783): warning #2203: Function 'mysql_get_optionv' can't be __stdcall, changed to __cdecl.
Building TestMariaDB.exe.
Done.
Build time: 750ms
Title: Re: Using MySQL C Connector 6.1.11
Post by: frankie on October 13, 2017, 05:14:25 PM
MariaDB have bugs in headers, varargs are not handled correctly.
Code: [Select]
Building TestMariaDB.obj.
C:\code\PellesC\MariaDB\include\mysql.h(444): warning #2203: Function 'mysql_load_plugin' can't be __stdcall, changed to __cdecl.
C:\code\PellesC\MariaDB\include\mysql.h(495): warning #2203: Function 'mariadb_get_infov' can't be __stdcall, changed to __cdecl.
C:\code\PellesC\MariaDB\include\mysql.h(572): warning #2203: Function 'mysql_optionsv' can't be __stdcall, changed to __cdecl.
C:\code\PellesC\MariaDB\include\mysql.h(573): warning #2203: Function 'mysql_get_optionv' can't be __stdcall, changed to __cdecl.
C:\code\PellesC\MariaDB\include\mysql.h(728): warning #2203: Function 'mariadb_get_infov' can't be __stdcall, changed to __cdecl.
C:\code\PellesC\MariaDB\include\mysql.h(782): warning #2203: Function 'mysql_optionsv' can't be __stdcall, changed to __cdecl.
C:\code\PellesC\MariaDB\include\mysql.h(783): warning #2203: Function 'mysql_get_optionv' can't be __stdcall, changed to __cdecl.
Building TestMariaDB.exe.
Done.
Build time: 750ms
That's are simple warnings, the problem is that MS compilers accepts also variadic functions declared as __stdcall.
Evidently the library was developed using MS...  >:(
Title: Re: Using MySQL C Connector 6.1.11
Post by: pjbrudal on October 15, 2017, 07:13:07 AM
Thank you, guys. The project now builds without error messages.
Title: Re: Using MySQL C Connector 6.1.11
Post by: pjbrudal on October 15, 2017, 08:14:58 AM
And after copying libmysql.dll from the connector folder to C:\Windows, the program also works :-) Thank you once more!