3

我在这个论坛上发现了一些关于相同错误的主题,但我没有在其中找到解决方案。

我正在尝试在 Ubuntu 11.04 上使用 C++ 和 Mysql 连接器。我的错误是(在遵循官方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"

提前谢谢大家

藤树

4

2 回答 2

0

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();
于 2011-09-22T14:19:15.700 回答
-1
LIBPATH = -L/usr/lib/ -lmysqlcppconn -lmysqlclient_r
于 2015-08-31T01:53:10.623 回答