Author Topic: Problem with --enable-auto-import with mysql++  (Read 16585 times)

Alexbad

  • Guest
Problem with --enable-auto-import with mysql++
« on: June 03, 2006, 12:37:53 am »
Hi,

Since a lot of time, I'm trying to use the API mysql++ in C++, with the ide Code::Blocks over Microsoft Windows XP Home Edition.

When I try to compile, after the linking of mysql_client.lib, I get a hundred of linker errors like that :

variable 'iob_' can't be auto-imported. Please read the ld's documentation about --enable-auto-import.

I tried to add --enable-runtime-pseudo-relloc in the linker options as someone told me in the mysql++ mailing list, it changes nothing.

Finally, here's the simple code I try to compile (an example that comes with mysql++, that's why I kept the copyright at first :

Code: C++
  1. /*
  2.     Copyright (C) 2005 Simax
  3.  
  4.     Connexion et Execution d'une requête en C++ console (VC8 - 2005 Express)
  5.     cette source utilise l'API MySQL version 5.x
  6.     j'ai placé le contenu des fichiers d'en-tête de l'API à l'adresse :
  7.     http://www.simax-server.info/api/API_MODIF_MYSQL_5.RAR
  8.     NOTE : j'ai modifiée l'API pour qu'elle puisse être utilisée sous Visual Studio 2005 Express
  9.     et je sais pas comment peuvent réagir les autres compilateurs
  10.  
  11.         This program is free software; you can redistribute it and/or modify
  12.     it under the terms of the GNU General Public License as published by
  13.     the Free Software Foundation; either version 2 of the License, or
  14.     (at your option) any later version.
  15.  
  16.     This program is distributed in the hope that it will be useful,
  17.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  18.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  19.     GNU General Public License for more details.
  20. */
  21.  
  22. #include <mysql.h>
  23. #include <iostream>
  24.  
  25. using namespace std;
  26.  
  27. #pragma comment(lib, "libmysql.lib") // libmysql.dll doit etre dans le meme rep.
  28.  
  29. int main(void)
  30. {
  31.  
  32.         MYSQL mysql;
  33.         const char *host  = "127.0.0.1"; // Adresse du serveur MySQL
  34.         const char *user  = "root"; // Nom d'utilisateur
  35.         const char *pass  = ""; // Mot de passe
  36.         const char *db    = "lapage2";  // Base de donnée
  37.         const char *query = "SELECT * FROM enligne"; // Requête à executer
  38.  
  39.         unsigned int num_fields;
  40.         unsigned int num_rows;
  41.  
  42.         MYSQL_RES *result;
  43.  
  44.  
  45.         system("cls");
  46.         cout << "\nSimax MTGO Mysql Connection\n---------------------------------------------\n\n";
  47.         cout << "Establishing Remote connection...........";
  48.         mysql_init(&mysql);
  49.         mysql_options(&mysql,MYSQL_READ_DEFAULT_GROUP,"main");
  50.  
  51.         if (!mysql_real_connect(&mysql,host,"root","","lapage2",0,NULL,0)) //connexion
  52.  
  53.                 {
  54.                 cout << "[Error !]\n\n";
  55.                 system("pause");
  56.                 return (0);
  57.                 }
  58.                 cout << "[Connected @ "; cout << &mysql; cout << "]\n";
  59.                 cout << "Sending Request..........................";
  60.  
  61.                 if (mysql_query(&mysql,query))
  62.                         {
  63.                                 cout << "[Error !]\n\n";
  64.                                 system("pause");
  65.                                 return(0);
  66.                         }
  67.                         else // requete OK
  68.                         {
  69.                                 cout << "[Sended]\n";
  70.                                 result = mysql_store_result(&mysql); // enregistrement du résultat
  71.                                 cout << "Result...................................";
  72.                                 if (result)
  73.                                 {
  74.                                         num_fields = mysql_num_fields(result); // champs trouvés
  75.                                         cout << "[";cout << num_fields;cout << " Field(s) founded for query]\n\n";
  76.                                         system("pause");
  77.                                 }
  78.                                 else
  79.                                 {
  80.                                         if(mysql_field_count(&mysql) == 0) // Pas de champs a renvoyer
  81.                                         {
  82.                                                 num_rows = mysql_affected_rows(&mysql);
  83.                                                 cout << "[no fields or bad SELECT request !]";
  84.                                                 system("pause");
  85.                                         }
  86.                                         else // Erreur inconnue
  87.                                         {
  88.                                         cout << "[BAD REQUEST !]";
  89.                                         system("pause");
  90.                                         }
  91.                         }
  92.                 }
  93.  
  94.  
  95.                 mysql_close(&mysql); // Fermeture de la connexion
  96.                 return(0);
  97. }

I know this code is done to be used on Visual C++ Express Edition, but I get the same mistake with this :

Code: C++
  1. #include <stdio.h>
  2. #include <winsock.h>
  3. #include <iostream.h>
  4. #include "mysql/include/mysql.h"
  5.  
  6. int main(int argc, char *argv[])
  7. {
  8.  
  9. MYSQL mysql;
  10.  
  11. mysql_init(&mysql);
  12. mysql_options(&mysql,MYSQL_READ_DEFAULT_GROUP,"testMySQL");
  13. if (!mysql_real_connect(&mysql,"localhost","root","","lapage",0,NULL,0))
  14. {
  15.     cout << "Connexion impossible!";
  16. }
  17. else
  18. {
  19.     cout << "Connexion réussie!";
  20. }
  21.  
  22.            cout << "Bonjour!";
  23.   int y;
  24.   scanf("%ld", y);
  25.   return 0;
  26. }
  27.  

and I'm sure this is not a directory/include problem, I corrected all of them by editing files concerned.

Thanks!

Offline Ceniza

  • Developer
  • Lives here!
  • *****
  • Posts: 1441
    • CenizaSOFT
Re: Problem with --enable-auto-import with mysql++
« Reply #1 on: June 03, 2006, 12:56:03 am »
The problem: you're trying to link against a .lib with MinGW.

VC++'s libraries have the .lib extension, GCC's (MinGW) libraries the .a extension. It'sn't just the extension, the library file itself is different.

You'll have to use VC++ to compile your program or get the .a somehow.

I just checked the site and I didn't see Windows binaries, only Linux binaries and sources, so you should try to build it with MinGW following the instructions in README.mingw.

Alexbad

  • Guest
Re: Problem with --enable-auto-import with mysql++
« Reply #2 on: June 03, 2006, 12:59:40 am »
Ok, I follow...

But I don't understand instructions about the makefile, and I'm not able to create makefile... Whatever, I'm gone a try and if it doesn't work anymore I ask you ;)

Alexbad

  • Guest
Re: Problem with --enable-auto-import with mysql++
« Reply #3 on: June 03, 2006, 01:08:54 am »
This is the contain of the README file :

Quote
Prerequisite: Create Import Library
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   Before you can build MySQL++ with MinGW, you will need to
   create a MinGW-compatible import library for MySQL's C API
   library.  Assuming you installed MySQL in c:\mysql and MySQL++
   in c\mysql++, the commands to do this are:

      mkdir c:\mysql\lib\opt
      cd c:\mysql\lib\opt
       dlltool -k -d c:\mysql++\libmysqlclient.def -l libmysqlclient.a


Building the Library and Example Programs
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   Now you can build MySQL++ with this command:
   
      mingw32-make -f Makefile.mingw

   Notice that we're using the MinGW-specific version of GNU
   make, not the Cygwin or MSYS versions.   This is in order to
   get proper path separator handling.

   If you didn't install MySQL in c:\mysql, it's probably simplest
   to just change the Makefile.mingw files.  Theoretically you
   could adjust the Bakefiles instead, but due to the way we're
   using Bakefile, it's a little difficult to rebuild Makefiles
   on Windows right now.

   If you want to change the install location, that is in
   install.bat.

You see, I don't know where I have to type the command "dlltool", I tried in a Ms-Dos Console, it didn't work...



Offline Ceniza

  • Developer
  • Lives here!
  • *****
  • Posts: 1441
    • CenizaSOFT
Re: Problem with --enable-auto-import with mysql++
« Reply #4 on: June 03, 2006, 01:27:40 am »
Quote from: README
mkdir c:\mysql\lib\opt
cd c:\mysql\lib\opt
dlltool -k -d c:\mysql++\libmysqlclient.def -l libmysqlclient.a

That makes the assumption the source of mysql++ is in c:\mysql++ and there you should have a file named libmysqlclient.def.

I downloaded the sources, decompressed them and it created a directory named mysql++-2.1.1. You just should rename it to mysql++ and move it to C:\.

Now open a console window and type those three lines.

Now cd c:\mysql++\lib followed by the other line: mingw32-make -f Makefile.mingw.

If you don't want debugging information in the library, add BUILD=release at the end of it.

Important: the Makefile assumes you have installed MySQL sources in C:\mysql, which isn't the default installation directory.

Just copy from your MySQL directory the include and lib directories to C:\mysql.

I just tried it as I wrote it and I got the .a :)

Offline TDragon

  • Lives here!
  • ****
  • Posts: 943
    • TDM-GCC
Re: Problem with --enable-auto-import with mysql++
« Reply #5 on: June 03, 2006, 01:30:29 am »
You see, I don't know where I have to type the command "dlltool", I tried in a Ms-Dos Console, it didn't work...
You're definitely on the right track. A command prompt is the correct place to use those three commands, and probably the only thing getting in the way is that the system doesn't know how to implicitly find "dlltool" (dlltool.exe). The quickest way to correct this is to add the directory containing it to the path temporarily, right before you use the dlltool command:
set PATH=%PATH%;C:\CodeBlocks\bin
(or whatever directory MinGW is installed in).
https://jmeubank.github.io/tdm-gcc/ - TDM-GCC compiler suite for Windows (GCC 9.2.0 2020-03-08, 32/64-bit, no extra DLLs)

Offline Ceniza

  • Developer
  • Lives here!
  • *****
  • Posts: 1441
    • CenizaSOFT
Re: Problem with --enable-auto-import with mysql++
« Reply #6 on: June 03, 2006, 01:57:16 am »
Trying to get the second code sample you provided compiled and linked wasn't straight/easy (even though it doesn't use mysql++ but just the plain mysql headers).

It uses old C++ style (needs some minor fixes), winsock.h really needs to be included before mysql.h, you have to set paths for includes and libraries, be sure two DLLs are in the PATH or in the same folder as your executable (MySQL suggests to add the path for one of those in the installation process), add two libraries in the correct order so it'll be able to link, ...

It won't be such a nice experience as you would want it to, but once you're done with all those details it should work lovely with Code::Blocks :)

Add to the previous installation procedure:
  cd c:\mysql++
  install.bat opt

Now you can create a new application (a new console application would be fine), change the main.cpp it created with a sample code that uses mysql++ and add this in Project->Build options:

[Linker: Link libraries]: mysqlpp, mysqlclient (add them in that order).
[Directories: Compiler]: C:\mysql++\include, C:\mysql\include (the order doesn't matter).
[Directories: Linker]: C:\mysql++\lib, C:\mysql\lib\opt (once again, the order doesn't matter).

Now you should be ready to hit build and almost get it to run (if c:\mysql++\lib is in the PATH or you copy c:\mysql++\lib\mysqlpp.dll to your executable's directory, it should run).

Just remember any mysql++ specific problem you better discuss it in the mysql++'s forums :)

Offline Alexbad

  • Multiple posting newcomer
  • *
  • Posts: 10
    • OwnBloog
Re: Problem with --enable-auto-import with mysql++
« Reply #7 on: June 03, 2006, 09:33:42 pm »
Sorry for the delay before my answer, I got problems with my mysql server (I was using EasyPHP, C/C++ includes don't come with easyphp :p) and I installed complete versions of the software.

I read your instructions, I finally got the libmysqlclient.a, I linked it and I get this from the linker :

Cannot find -lmysqlclient

And I didn't put any option in the linker options, I just add the .a library. Thanks for your precious help ;)

Quote from: Ceniza
Just remember any mysql++ specific problem you better discuss it in the mysql++'s forums :)
You know, I'm used to speak french, I will not make on purpose to stay on english forums  :lol:
« Last Edit: June 03, 2006, 11:30:06 pm by Alexbad »
:) Alexbad :)

Offline Ceniza

  • Developer
  • Lives here!
  • *****
  • Posts: 1441
    • CenizaSOFT
Re: Problem with --enable-auto-import with mysql++
« Reply #8 on: June 04, 2006, 01:20:23 am »
Quote from: Alexbad
Cannot find -lmysqlclient

Could you check if libmysqlclient.a exists in C:\mysql\lib\opt? If it does, be sure that path is in [Directories: Linker], if not, search for it and add its path to [Directories: Linker].

Offline Alexbad

  • Multiple posting newcomer
  • *
  • Posts: 10
    • OwnBloog
Re: Problem with --enable-auto-import with mysql++
« Reply #9 on: June 04, 2006, 01:26:49 am »
But I'm sure the path is okay because I used the function of Code::Blocks "Add library" :

You can see a print screen of my linker options : http://www.la-page.qc.ca/membres/mbr1/screencb.PNG

If someone feel able to resolve the problem, I can let him do it by giving him the control of my computer...
:) Alexbad :)

Offline Ceniza

  • Developer
  • Lives here!
  • *****
  • Posts: 1441
    • CenizaSOFT
Re: Problem with --enable-auto-import with mysql++
« Reply #10 on: June 04, 2006, 03:49:48 am »
I see you added it with the whole (relative) path, and if you in fact did it using "Add library", it should find it.

I just tried it here that way and it works, even though mine looks like this: ..\..\..\..\mysql\lib\opt\libmysqlclient.a

By the way, which version of Code::Blocks are you using? RC2? Nightly? Which revision?

Offline Alexbad

  • Multiple posting newcomer
  • *
  • Posts: 10
    • OwnBloog
Re: Problem with --enable-auto-import with mysql++
« Reply #11 on: June 04, 2006, 03:53:19 am »
Code::Blocks Version 1.0, that's what is wrote in "Help -> About"

EDIT : But my libmysqlclient isn't in the MySQL directory on the print screen, it's in the C::B's bin directory, I moved it int mysql/lib/opt and it changed nothing
:) Alexbad :)

Offline Ceniza

  • Developer
  • Lives here!
  • *****
  • Posts: 1441
    • CenizaSOFT
Re: Problem with --enable-auto-import with mysql++
« Reply #12 on: June 04, 2006, 04:14:54 am »
Comparing the look of your Project's Build Options window with mine, I got an extra label, so you're maybe using RC2.

Please visit this link, read it carefully, install a Nightly build and try again.

Offline Alexbad

  • Multiple posting newcomer
  • *
  • Posts: 10
    • OwnBloog
Re: Problem with --enable-auto-import with mysql++
« Reply #13 on: June 04, 2006, 04:37:29 am »
I followed steps described : I don't find the file CB nightly in the archive, and I extracted mingwm10.dll, I always have problems.

I don't know why but now, mistakes are :



and MySQL Documentation describe this error : http://dev.mysql.com/doc/refman/5.0/fr/link-errors.html

but I don't really understand their solution...

EDIT : Sorry, the link in english : http://dev.mysql.com/doc/refman/5.0/en/link-errors.html
:) Alexbad :)

Offline Michael

  • Lives here!
  • ****
  • Posts: 1608
Re: Problem with --enable-auto-import with mysql++
« Reply #14 on: June 04, 2006, 04:45:56 am »
but I don't really understand their solution...

EDIT : Sorry, the link in english : http://dev.mysql.com/doc/refman/5.0/en/link-errors.html


Hello,

What exactly you do not understand :?? It seems quite good explained.

Best wishes,
Michael

Offline Alexbad

  • Multiple posting newcomer
  • *
  • Posts: 10
    • OwnBloog
Re: Problem with --enable-auto-import with mysql++
« Reply #15 on: June 04, 2006, 04:47:08 am »
Simply because it doesn't work anymore, so I think I do something wrong...

Ceniza told me that the .lib extension were just supported by VC, and I don't find any mysqlclient.a.  Of course I get a file named libmysqlclient.a but not mysqlclient.a
« Last Edit: June 04, 2006, 04:52:58 am by Alexbad »
:) Alexbad :)

Offline Ceniza

  • Developer
  • Lives here!
  • *****
  • Posts: 1441
    • CenizaSOFT
Re: Problem with --enable-auto-import with mysql++
« Reply #16 on: June 04, 2006, 04:53:02 am »
Latest nightly (03 June)

libmysqlclient.a is the right name. Please install the Nightly and try again.

Offline Alexbad

  • Multiple posting newcomer
  • *
  • Posts: 10
    • OwnBloog
Re: Problem with --enable-auto-import with mysql++
« Reply #17 on: June 04, 2006, 05:45:13 am »
Ok, I think this time the Nightly build is installed : the interface is changed and there's a new tab in the build options.

I tried to compile my code, I get a popup telling me :

"It seems that this project has not been build yet. Do you want to build it now?"

Of course I answer yes but the same popup reopen, again and again, until I click on "Cancel", and my program doesn't launch. This problem has nothing to see with mysql because I have it with all my old c::b project... and even with this code :

Code: C++
  1. #include <iostream>
  2.  
  3. int main()
  4. {
  5.         printf("Hello world");
  6. }

And when I click on "Rebuild" :



Thanks again for your patience :)
:) Alexbad :)

Offline Ceniza

  • Developer
  • Lives here!
  • *****
  • Posts: 1441
    • CenizaSOFT
Re: Problem with --enable-auto-import with mysql++
« Reply #18 on: June 04, 2006, 06:40:20 am »
My guess: you didn't configure the Nightly to use RC2's compiler, so it's unable to find mingw32-g++.exe

Check "Settings->Compiler and debugger" then the tab "Programs". "Compiler's installation directory" must point to the directory where RC2's compiler was installed (it should have directories like bin, include, lib, ...). My guess is it must be somewhere in C:\Program files\CodeBlocks (since I never installed the RC2 version that includes the compiler I don't have idea where it's saved).

Searching for mingw32-g++.exe should give you the right path, and it should be inside a directory named bin. Just add that path in "Compiler's installation directory", but don't include the "bin" directory on it.

Offline Alexbad

  • Multiple posting newcomer
  • *
  • Posts: 10
    • OwnBloog
Re: Problem with --enable-auto-import with mysql++
« Reply #19 on: June 04, 2006, 04:09:38 pm »
It works now for the compiler, I don't know why but it was the DevCpp's directories, I changed them...

Now, I always get a undefined reference, here you can see all : http://www.la-page.qc.ca/bd.PNG
:) Alexbad :)

Offline Michael

  • Lives here!
  • ****
  • Posts: 1608
Re: Problem with --enable-auto-import with mysql++
« Reply #20 on: June 04, 2006, 05:12:45 pm »
It works now for the compiler, I don't know why but it was the DevCpp's directories, I changed them...

Hello,

I think it would be better to have a separate MinGW installation rather than to use the MinGW of RC2.

Best wishes,
Michael

Offline Ceniza

  • Developer
  • Lives here!
  • *****
  • Posts: 1441
    • CenizaSOFT
Re: Problem with --enable-auto-import with mysql++
« Reply #21 on: June 04, 2006, 08:41:26 pm »
Everything seems to be OK with your configuration. There's no complaint about that library not being found this time, but it cannot find the method...

Could you post the file size of that library to compare with mine? I'm getting out of ideas now :)

Offline Alexbad

  • Multiple posting newcomer
  • *
  • Posts: 10
    • OwnBloog
Re: Problem with --enable-auto-import with mysql++
« Reply #22 on: June 04, 2006, 08:44:38 pm »
libmysqlclient.a : 2 kb

I think about it, this is not too much...
:) Alexbad :)

Offline Ceniza

  • Developer
  • Lives here!
  • *****
  • Posts: 1441
    • CenizaSOFT
Re: Problem with --enable-auto-import with mysql++
« Reply #23 on: June 04, 2006, 08:51:14 pm »
107KB here.

Try the steps to build the library again. Maybe you missed something :)

Offline Alexbad

  • Multiple posting newcomer
  • *
  • Posts: 10
    • OwnBloog
Re: Problem with --enable-auto-import with mysql++
« Reply #24 on: June 04, 2006, 08:57:40 pm »
NICE!!! :D :D

Now it works fine, thanks a lot for your help Ceniza, Michael and all the others!
:) Alexbad :)

Offline Matreju

  • Multiple posting newcomer
  • *
  • Posts: 12
Re: Problem with --enable-auto-import with mysql++
« Reply #25 on: June 21, 2006, 08:17:23 pm »
Identically Problem..

Code :

    mysqlpp::Connection DBCon = new mysqlpp::Connection();
    ci = DBCon.client_info();
  try {
    DBCon.connect(database,host,dbuser,dbpasswd);
  }
  catch(const mysqlpp::Exception& er) {
       error=DBCon.error();
       cerr << er.what() << endl;
  }
    mysqlpp::Query CategoriesQuery =  DBCon.query();


Linker error :/wxWidgets-2.6.3/include/wx/object.h:(.text$_ZN7mysqlpp5QueryD1Ev[mysqlpp::Query::~Query()]+0x52): variable 'vtable for mysqlpp::Query' can't be auto-imported. Please read the documentation for ld's --enable-auto-import for details.


At debugging the DBCon object is ok and have an connect.
But why there is no Query Object ?
( When i comment mysqlpp::Query CategoriesQuery =  DBCon.query(); out all works fine )

The .a Files are generated as in documentation .
« Last Edit: June 21, 2006, 08:19:08 pm by Matreju »

Offline Ceniza

  • Developer
  • Lives here!
  • *****
  • Posts: 1441
    • CenizaSOFT
Re: Problem with --enable-auto-import with mysql++
« Reply #26 on: June 22, 2006, 03:10:43 am »
That error looks really strange. Why in wx/object.h in the first place?

You should ask the mysql++ people about it. I cannot help you with this one :(

Offline Matreju

  • Multiple posting newcomer
  • *
  • Posts: 12
Re: Problem with --enable-auto-import with mysql++
« Reply #27 on: June 22, 2006, 11:14:40 am »
I have make an post in mysql++ forums. What i have found is thats looke like a mingw port problem of mysql++
The exports arent allowed from mingw  . But mysql wrote thats correct and mingw have an error.
I am not an expert to mingw at this time so i dont know who is right.

Have anyone compiled it under Windows XP , gcc-3.4.4 (mingw special ) so it works ? Maybe other options or changing the sources.
I have used the original mingw Files from mysql++  ( mingw32-make -f Makefile.mingw BUILD=debug ..All libs build well. )

Offline Ceniza

  • Developer
  • Lives here!
  • *****
  • Posts: 1441
    • CenizaSOFT
Re: Problem with --enable-auto-import with mysql++
« Reply #28 on: June 22, 2006, 08:58:44 pm »
Well, I just tried your example (had to add a few types to make it compile) and it was the output:

Quote from: Build log
-------------- Build: default in test ---------------
mingw32-g++.exe  -IC:\mysql++\include -IC:\mysql\include -IC:\MinGW\include  -c main.cpp -o .objs\main.o
mingw32-g++.exe -LC:\mysql++\lib -LC:\mysql\lib\opt -LC:\MinGW\lib  -o test.exe .objs\main.o    -lmysqlpp -lmysqlclient
Info: resolving vtable for mysqlpp::Queryby linking to __imp___ZTVN7mysqlpp5QueryE (auto-import)
Info: resolving VTT for mysqlpp::Queryby linking to __imp___ZTTN7mysqlpp5QueryE (auto-import)
Process terminated with status 0 (0 minutes, 3 seconds)
0 errors, 0 warnings

Those auto-imports look ugly but even that way it compiled.

Could you try following my steps to compile the library? At least I got it working that way here.