C++ Connection to MySQL using mysql++

387 Views Asked by At

I am pretty new to C++ and to Linux (Ubuntu), so please don't kill me if I am a bit slow in understanding.

I try to establish a connection to my SQL DB using C++ and the MySQL Connector mysql++. As for the development environment, I use Eclipse. As for the compiler, the standard compiler for Linux (g++).

After 9 hours of Google, I am pretty optimistic that I have to install all necessary libraries. But well, as it's not working, maybe not.

The C++ code I try to use is:

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

using namespace mysqlpp;
using namespace std;

int main() {
    try {
        Connection conn(false);
        conn.connect("DB", "127.0.1.1:3306", "root", "root");
        Query query = conn.query();
    } catch (BadQuery er) { // handle any connection or
        // query errors that may come up
        cerr << "Error: " << er.what() << endl;
        return -1;
    } catch (const BadConversion& er) {
        // Handle bad conversions
        cerr << "Conversion error: " << er.what() << endl <<
                "\tretrieved data size: " << er.retrieved <<
                ", actual size: " << er.actual_size << endl;
        return -1;
    } catch (const Exception& er) {
        // Catch-all for any other MySQL++ exceptions
        cerr << "Error: " << er.what() << endl;
        return -1;
    }
    cout<<"Sucesss";
}

And the error I get when building the project:

Invoking: GCC C++ Linker
g++  -o "MySQL Training"  ./Main.o ./aead.o   
./aead.o: In Funktion `main':
/home/florian/workspace/MySQL Training/Debug/../aead.cpp:5: Mehrfachdefinition von `main'
./Main.o:/home/florian/workspace/MySQL Training/Debug/../Main.cpp:8: first defined here
./Main.o: In Funktion `main':
Main.cpp:(.text+0x20): Nicht definierter Verweis auf `mysqlpp::Connection::Connection(bool)'
Main.cpp:(.text+0x4a): Nicht definierter Verweis auf `mysqlpp::Connection::connect(char const*, char const*, char const*, char const*, unsigned int)'
Main.cpp:(.text+0x68): Nicht definierter Verweis auf `mysqlpp::Connection::query(char const*)'
Main.cpp:(.text+0x86): Nicht definierter Verweis auf `mysqlpp::Connection::~Connection()'
Main.cpp:(.text+0xb6): Nicht definierter Verweis auf `mysqlpp::Connection::~Connection()'
collect2: error: ld returned 1 exit status
make: *** [MySQL Training] Fehler 1

18:22:13 Build Finished (took 908ms)

I also had some problems installing mysql++ from source (./configure can't find mysqlclient library evenso mysql client and connector are installed).

Hope you can help me as I am out of ideas and Google pages.

0

There are 0 best solutions below