User forums > Help

Problem with --enable-auto-import with mysql++

(1/6) > >>

Alexbad:
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);
}
--- End code ---

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;
}

--- End code ---

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

Thanks!

Ceniza:
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:
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:
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.
--- End quote ---

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


Ceniza:

--- Quote from: README ---mkdir c:\mysql\lib\opt
cd c:\mysql\lib\opt
dlltool -k -d c:\mysql++\libmysqlclient.def -l libmysqlclient.a
--- End quote ---

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

Navigation

[0] Message Index

[#] Next page

Go to full version