未定义对sql :: mysql :: get_driver_instance()

时间:2018-11-11 14:44:13

标签: c++ mysql linux linker centos

如标题中所述,我在编译代码时遇到了问题。我在gcc编译器中使用CentOs7,我正在尝试编译连接到sql服务器的c ++代码。每当我尝试编译代码时,都会向我显示链接错误 未定义对sql :: mysql :: get_driver_instance()的引用。我已经被困了一天多了,我无法解决这个问题。 enter image description here。这就是我的文件夹结构。我正在使用c ++ / connector 8.0版本。我尝试使用命令

添加共享库libmysqlcppconn8.so
g++ -L/home/mysq/Schreibtisch/codeendversion/lib64/libmysqlcppconn8 sql-query-test.cpp

但是没有用。希望有人可以帮助我解决这个问题。预先感谢

#include <stdlib.h>
#include <iostream>
#include <sstream>
#include <stdexcept>
#include "jdbc/mysql_connection.h"
#include "jdbc/mysql_driver.h"
#include "jdbc/mysql_error.h"
#include "jdbc/cppconn/driver.h"
#include "jdbc/cppconn/exception.h"
#include "jdbc/cppconn/resultset.h"
#include "jdbc/cppconn/statement.h"
#include "jdbc/cppconn/prepared_statement.h"


#define HOST "localhost"
#define BENUTZER "user"
#define PASSWORT "pass"
#define DATENBANK "credentials"

using namespace sql::mysql;
using namespace std;

int main(int argc, const char **argv)
{
  string url(argc >= 2 ? argv[1] : HOST);
  const string user(argc >= 3 ? argv[2] : BENUTZER);
  const string pass(argc >= 4 ? argv[3] : PASSWORT);
  const string database(argc >= 5 ? argv[4] : DATENBANK);

  try {


sql::mysql::MySQL_Driver *driver;
sql::Connection *con;
sql::Statement *stmt;
sql::ResultSet *res;

driver = sql::mysql::get_driver_instance();
con = driver->connect("tcp://127.0.0.1:3306", "root", "samuel123");
con->setSchema("SQLServer");

stmt = con->createStatement();
res = stmt->executeQuery("select hostname From 'credentials'");


delete stmt;
delete con;
delete res;



  } catch (sql::SQLException &e) {

    cout << "# ERR: SQLException in " << _FILE_;
    cout << "(" << _FUNCTION_ << ") on line " << _LINE_ << endl;
    cout << "# ERR: " << e.what();
    cout << " (MySQL error code: " << e.getErrorCode();
    cout << ", SQLState: " << e.getSQLState() << " )" << endl;

    return EXIT_FAILURE;
  }

  cout << "Done." << endl;
  return EXIT_SUCCESS;

}

/ * passwort mysql服务器:root / mysql * /

0 个答案:

没有答案