NO

Author Topic: Using MySQL C Connector 6.1.11  (Read 5942 times)

pjbrudal

  • Guest
Using MySQL C Connector 6.1.11
« on: October 12, 2017, 05: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.

Jokaste

  • Guest
Re: Using MySQL C Connector 6.1.11
« Reply #1 on: October 12, 2017, 06:25:30 PM »
try #include "crtdbg.h" rather than #include <crtdbg.h>

Offline frankie

  • Global Moderator
  • Member
  • *****
  • Posts: 2113
Re: Using MySQL C Connector 6.1.11
« Reply #2 on: October 12, 2017, 07: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?
"It is better to be hated for what you are than to be loved for what you are not." - Andre Gide

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 2115
Re: Using MySQL C Connector 6.1.11
« Reply #3 on: October 12, 2017, 08: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")
« Last Edit: October 12, 2017, 08:12:59 PM by TimoVJL »
May the source be with you

pjbrudal

  • Guest
Re: Using MySQL C Connector 6.1.11
« Reply #4 on: October 13, 2017, 09: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.

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 2115
Re: Using MySQL C Connector 6.1.11
« Reply #5 on: October 13, 2017, 11:03:13 AM »
use pocc.exe option -Ze Enable Microsoft extensions
and check correct library libmysql.lib/libmariadb.lib is it for i386 ?
May the source be with you

pjbrudal

  • Guest
Re: Using MySQL C Connector 6.1.11
« Reply #6 on: October 13, 2017, 02: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.

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 2115
Re: Using MySQL C Connector 6.1.11
« Reply #7 on: October 13, 2017, 04: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
« Last Edit: October 13, 2017, 05:08:57 PM by TimoVJL »
May the source be with you

Offline frankie

  • Global Moderator
  • Member
  • *****
  • Posts: 2113
Re: Using MySQL C Connector 6.1.11
« Reply #8 on: October 13, 2017, 06: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...  >:(
"It is better to be hated for what you are than to be loved for what you are not." - Andre Gide

pjbrudal

  • Guest
Re: Using MySQL C Connector 6.1.11
« Reply #9 on: October 15, 2017, 08:13:07 AM »
Thank you, guys. The project now builds without error messages.

pjbrudal

  • Guest
Re: Using MySQL C Connector 6.1.11
« Reply #10 on: October 15, 2017, 09:14:58 AM »
And after copying libmysql.dll from the connector folder to C:\Windows, the program also works :-) Thank you once more!