开发者

C++ / Mysql Connector : undefined reference to `get_driver_instance'

开发者 https://www.devze.com 2023-04-06 13:25 出处:网络
I\'ve found some topics on this forum concerning the same error, but I didn\'t find the solution in it.

I've found some topics on this forum concerning the same error, but I didn't find the solution in it.

I'm trying to make work C++ & Mysql Connector on Ubuntu 11.04. My error is (after following official Mysql tutorial)

/tmp/ccDmH4pd.o: In function `main':
mysql.cpp:(.text+0xb): undefined reference to `get_driver_instance'
collect2: ld returned 1 exit status

Here is my code :

int main(){     
    sql::Driver*        driver; // Create a pointer to a MySQL driver object
    sql::Connection*    dbConn; // Create a pointer to a database connection object
    sql::Statement*     stmt;   // Create a pointer to a Statement object to hold our SQL commands
    sql::ResultSet*     res;    // Create a pointer to a ResultSet object to hold the results of any queries we run

    driver = get_driver_instance();
    dbConn = driver->connect(server, username, password);


        delete dbConn;
        return 0;
    }

Here are my includes :

#include "mysql_driver.h"
#include "mysql_connection.h"

// Include the Connector/C++ headers
#include "cppconn/driver.h"
#include "cppconn/exception.h"
#include "cppconn/resultset.h"
#include "cppconn/statement.h"

Thanks in adva开发者_如何学运维nce everybody

Touki


The get_driver_instance() function is not in the global namespace but in ::sql::mysql. So you have to use the proper name:

::sql::Driver *driver = ::sql::mysql::get_driver_instance();


LIBPATH = -L/usr/lib/ -lmysqlcppconn -lmysqlclient_r
0

精彩评论

暂无评论...
验证码 换一张
取 消