Соединитель C ++ / Mysql: неопределенная ссылка на get_driver_instance - PullRequest
3 голосов
/ 22 сентября 2011

На этом форуме я нашел несколько тем, касающихся той же ошибки, но я не нашел в ней решения.

Я пытаюсь заставить работать C ++ и Mysql Connector в Ubuntu 11.04. Моя ошибка (после официального урока Mysql)

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

Вот мой код:

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

Вот мои включает:

#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"

Спасибо всем заранее

Touki

Ответы [ 2 ]

0 голосов
/ 31 августа 2015
LIBPATH = -L/usr/lib/ -lmysqlcppconn -lmysqlclient_r
0 голосов
/ 22 сентября 2011

Функция get_driver_instance() находится не в глобальном пространстве имен, а в :: sql :: mysql. Поэтому вы должны использовать правильное имя:

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