C++ – MySQL Connector C++ – make Error 1

clinuxmakefileMySQL

I'm writing an application in C++ (using Eclipse with Linux GCC) that's supposed to interact with my MySQL server.
I've downloaded the MySQL Connector C++ a, precompiled, and copied the files into the directories (/usr/lib, /usr/include). I've referenced in in the GCC C++ Linker Section of the Project Properties in Eclipse ( "mysqlcppconn"). My code comes directly from the MySQL Reference (Hello World) except I removed error handling and the delete statements at the end (I'm not even getting there so whats the point)

#include <stdlib.h>
#include <iostream>
#include "mysql_connection.h"
#include "mysql_driver.h"
#include <cppconn/driver.h>
#include <cppconn/exception.h>
#include <cppconn/resultset.h>
#include <cppconn/statement.h>
using namespace std;

int main(void)
{
  sql::Driver *driver;
  sql::Connection *con;
  sql::Statement *stmt;
  sql::ResultSet *res;

  driver = get_driver_instance();
  con = driver->connect("tcp://127.0.0.1:3306", "root", "root");
  con->setSchema("test");

  stmt = con->createStatement();
  res = stmt->executeQuery("SELECT 'Hello World!' AS _message");

  while (res->next()) 
  {
    cout << "\t... MySQL replies: ";
    cout << res->getString("_message") << endl;
    cout << "\t... MySQL says it again: ";
    cout << res->getString(1) << endl;
  }  
return EXIT_SUCCESS;
}

now when I compile this, It gives me a make error 1, which the man page says means I need to recompile my packages. I've tried it, it doesn't work.

I seem to have hit dead ends everywhere. Can anyone tell me how to fix this problem? (make could really tell me what I should recompile.) Anyone have any tips/suggestions/ideas where I went wrong?

Edit – Chagned the code a bit, but the general idea is the same.

Update – If I use the terminal instead of exlipse to make, it tells me that the problem is obviously that the connector wants libstdc++.so.5 whilst I have libstdc++.so.6.

Best Answer

The Solution is quite simple - compile your own Connector. I did it with the 1.0.5 version of the Connector. to do it, you need to install the package via

sudo apt-get install mysql-client

In the directory of the source package you downloaded (and extracted), type

cmake .

apparently, in three files of the driver, references are made to snprintf and printf, without including the stdio.h header. I added

#include <stdio.h>

to each file and then, in the terminal, typed

make

then, I copied the Files to my lib directory

sudo cp path/to/driver/libmysqlcppconn* /usr/lib/

and everythign worked a charm.