Author Topic: Problem with --enable-auto-import with mysql++  (Read 22314 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: cpp
/*
    Copyright (C) 2005 Simax

    Connexion et Execution d'une requête en C++ console (VC8 - 2005 Express)
    cette source utilise l'API MySQL version 5.x
    j'ai placé le contenu des fichiers d'en-tête de l'API à l'adresse :
    http://www.simax-server.info/api/API_MODIF_MYSQL_5.RAR
    NOTE : j'ai modifiée l'API pour qu'elle puisse être utilisée sous Visual Studio 2005 Express
    et je sais pas comment peuvent réagir les autres compilateurs

This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.
*/

#include <mysql.h>
#include <iostream>

using namespace std;

#pragma comment(lib, "libmysql.lib") // libmysql.dll doit etre dans le meme rep.

int main(void)
{

MYSQL mysql;
const char *host  = "127.0.0.1"; // Adresse du serveur MySQL
const char *user  = "root"; // Nom d'utilisateur
const char *pass  = ""; // Mot de passe
const char *db    = "lapage2"; // Base de donnée
const char *query = "SELECT * FROM enligne"; // Requête à executer

unsigned int num_fields;
unsigned int num_rows;

MYSQL_RES *result;


system("cls");
cout << "\nSimax MTGO Mysql Connection\n---------------------------------------------\n\n";
cout << "Establishing Remote connection...........";
mysql_init(&mysql);
mysql_options(&mysql,MYSQL_READ_DEFAULT_GROUP,"main");

if (!mysql_real_connect(&mysql,host,"root","","lapage2",0,NULL,0)) //connexion

{
cout << "[Error !]\n\n";
system("pause");
return (0);
}
cout << "[Connected @ "; cout << &mysql; cout << "]\n";
cout << "Sending Request..........................";

if (mysql_query(&mysql,query))
{
cout << "[Error !]\n\n";
system("pause");
return(0);
}
else // requete OK
{
cout << "[Sended]\n";
result = mysql_store_result(&mysql); // enregistrement du résultat
cout << "Result...................................";
if (result)
{
num_fields = mysql_num_fields(result); // champs trouvés
cout << "[";cout << num_fields;cout << " Field(s) founded for query]\n\n";
system("pause");
}
else
{
if(mysql_field_count(&mysql) == 0) // Pas de champs a renvoyer
{
num_rows = mysql_affected_rows(&mysql);
cout << "[no fields or bad SELECT request !]";
system("pause");
}
else // Erreur inconnue
{
cout << "[BAD REQUEST !]";
system("pause");
}
}
}


mysql_close(&mysql); // Fermeture de la connexion
return(0);
}

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

Code: cpp
#include <stdio.h>
#include <winsock.h>
#include <iostream.h>
#include "mysql/include/mysql.h"

int main(int argc, char *argv[])
{

MYSQL mysql;

mysql_init(&mysql);
mysql_options(&mysql,MYSQL_READ_DEFAULT_GROUP,"testMySQL");
if (!mysql_real_connect(&mysql,"localhost","root","","lapage",0,NULL,0))
{
    cout << "Connexion impossible!";
}
else
{
    cout << "Connexion réussie!";
}

           cout << "Bonjour!";
  int y;
  scanf("%ld", y);
  return 0;
}

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 :)

Alexbad

  • Guest
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 »

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].

Alexbad

  • Guest
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...

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?

Alexbad

  • Guest
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

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.

Alexbad

  • Guest
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

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