NullBy7e
NullBy7e

Reputation: 546

Compile with C++ & MySQL on Debian using MINGW32

I cannot get this to compile, I had to move around the files abit to get them included.

COMPILE.SH

#!/bin/bash
i586-mingw32msvc-g++ -o widget.exe main.cpp -I /usr/include/boost/ -L /usr/lib/x86_64-linux-gnu/libmysqlclient.so

ERROR

/tmp/cci9fwk8.o:main.cpp:(.text+0x526): undefined reference to `__imp___ZN3sql5mysql19get_driver_instanceEv'
collect2: ld returned 1 exit status

I found more than 10 guides and I followed them exactly, installing all dependencies, adding the mysqlclient etc and nothing works.

MAIN.CPP (JUST A PART, REST OF CODE IS NOT NEEDED)

    #include <cstdlib>
    #include <iostream>
    #include <string>
    #include <sstream>
    #include <cstdio>
    #include <windows.h>
    #include <fstream>
    #include <stdio.h>
    #include <direct.h>
    #include "/usr/include/cppconn/mysql_connection.h"
    #include "/usr/include/cppconn/mysql_driver.h"
    #include </usr/include/cppconn/cppconn/driver.h>
    #include </usr/include/cppconn/cppconn/exception.h>
    #include </usr/include/cppconn/cppconn/resultset.h>
    #include </usr/include/cppconn/cppconn/statement.h>
    using namespace std;


    sql::Connection *con;
    sql::Statement *stmt;
    sql::ResultSet *res;
    sql::mysql::MySQL_Driver *driver;
    driver = sql::mysql::get_driver_instance();
    con = driver->connect("", "", "");
    con->setSchema("");

ldd /usr/lib/x86_64-linux-gnu/libmysqlclient.so

   linux-vdso.so.1 =>  (0x00007fff21eba000)
        libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007fb027f52000)
        libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007fb027d3b000)
        libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007fb027b36000)
        librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007fb02792e000)
        libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007fb027627000)
        libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007fb0273a4000)
        libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007fb02718e000)
        libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fb026e03000)
        /lib64/ld-linux-x86-64.so.2 (0x00007fb0286c0000)

Upvotes: 0

Views: 416

Answers (1)

Luca Davanzo
Luca Davanzo

Reputation: 21520

Usually, errors like:

undefined reference to `__imp___ZN3sql5mysql19get_driver_instanceEv'

happens when:

  • there are not implemented methods
  • you have two or more version of library
  • header is in version x, source in vesion y.

Tell you what to do it's a bit difficult if you don't have some linux skills... maybe mysql use a different version of libboost, I'm not sure.

Try:

ldd /usr/lib/x86_64-linux-gnu/libmysqlclient.so

This show you what libraries is needed by libmysqlclient.so

If there're a lot of dependecies, you can:

ldd /usr/lib/x86_64-linux-gnu/libmysqlclient.so | grep boost

And check if boost version is the same:

cat /usr/include/boost/version.hpp | grep "BOOST_LIB_VERSION"

edit:

By the way I suggest you to compile with:

-I /usr/include -L /usr/lib -lcppconn

that could be not necessary, but just for sure. And then include in main in this way:

#include <cppconn/mysql_connection.h>
#include <cppconn/mysql_driver.h>
#include <cppconn/cppconn/driver.h>
#include <cppconn/cppconn/exception.h>
#include <cppconn/cppconn/resultset.h>
#include <cppconn/cppconn/statement.h>

All with <>, and not with "".

Upvotes: 1

Related Questions